package com.ruoyi.system.gen.impl;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.service.IGameAttributeService;
import com.ruoyi.system.V2.inter.mapper.SalePartnerMapper;
import com.ruoyi.system.V2.recycle.mapper.AttributeMapper;
import com.ruoyi.system.gen.IGenAPI;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.model.domain.Attribute;
import com.ruoyi.system.model.mapper.SkinImgMapper;
import com.ruoyi.system.model.service.UploadService;
import com.ruoyi.system.model.untl.ImageUtils;
import com.ruoyi.system.outto.core.MapUntils;
import com.ruoyi.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sun.misc.BASE64Encoder;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/21 9:20
 */
@Slf4j
@Service
public class GenApiImpl implements IGenAPI {

    @Resource
    private AttributeMapper attributeMapper;

    @Resource
    private SkinImgMapper skinImgMapper;

    private static String key = "x8logf11d6o898l83botgg105c9ky83rjoi";

    private static String gengerImg = "genger-img/";

    @Autowired
    private UploadService uploadService;

    @Resource
    private SysDictDataMapper sysDictDataMapper;

    @Autowired
    IGameAttributeService gameAttributeService;

    @Resource
    SalePartnerMapper salePartnerMapper;


    @Resource
    private SysDictDataMapper dictDataMapper;
    @Resource
    private AuthenticationManager authenticationManager;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private IGenAPI genAPI;
    @Autowired
    private RedisCache redisCache;

    @Override
    public List<JSONObject> getRoleId(String yingdiId) {

        List<JSONObject> maps = testRoleList(yingdiId);
        return maps;
    }

    @Override
    public Map<String, Object> genTitle(String yingdiId, String roleId) {

        Map<String, Object> stringObjectMap = testRoleInfo(yingdiId, roleId);

        return stringObjectMap;
    }

    //    Map<String, Object> genTitleBack(String campId, String roleId,String ifImg);
    @Override
    @Transactional
    public Map<String, Object> genTitleBack(Map<String, Object> titleParams) {
        String yingdiId = MapUtils.getString(titleParams, "campId");
        String roleId = MapUtils.getString(titleParams, "roleId");

        String url = "";
        String username = "";
        String pwd = "";
        String path = "qrCode/wzry/wzryData";

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
            }
            if ("username".equals(dictData.getDictLabel())) {
                username = dictData.getDictValue();
            } else if ("pwd".equals(dictData.getDictLabel())) {
                pwd = dictData.getDictValue();
            }
        }

        Map<String, Object> params = new HashMap<>();
        params.put("username", username);
        params.put("pwd", pwd);
        params.put("campId", yingdiId);
        params.put("roleId", roleId);

        String res = HttpUtil.get(url + path, params);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {
            String data = jsonObject.getString("data");
            return JSONObject.parseObject(data);
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }
    }
//    @Override   旧方法
//    public Map<String, Object> genTitleBack_old(Map<String, Object> titleParams) {
//
//        String yingdiId = MapUtils.getString(titleParams, "campId");
//        String roleId = MapUtils.getString(titleParams, "roleId");
//
//        Map<String, Object> resultMap = new HashMap<>();
//
//        Map<String, Object> skinMap = new HashMap<>();
//
//        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("yingdiToken");
//        String token = sysDictDataList.get(0).getDictValue();
//        String userId = sysDictDataList.get(0).getDictLabel();
//
//        String roleUrl = "https://ssl.kohsocialapp.qq.com:10001/game/battleprofile";
//
//
//        Map<String, Object> paramsRoleList = new HashMap<>();
//        paramsRoleList.put("friendUserId", yingdiId);
//        paramsRoleList.put("roleId", roleId);
//        paramsRoleList.put("gameId", "20001");
//        paramsRoleList.put("token", token);
////        paramsRoleList.put("userId", "493258559");
//        paramsRoleList.put("userId", userId);
//        paramsRoleList.put("cClientVersionName", "6.72.301");
//
//        Map<String, Object> head = new HashMap<>();
//
//        head.put("content-type", "application/x-www-form-urlencoded");
//
//        String roleList = "";
//        try {
//            roleList = HttpUtils.doPostForm(roleUrl, paramsRoleList, null);
//        } catch (Exception e) {
//            settoken(sysDictDataList);
//        }
//
//        JSONObject roleJson = JSON.parseObject(roleList);
//        String result = roleJson.getString("result");
//        if ("0".equals(result)) {
//            String roleData = roleJson.getString("data");
//            JSONObject roleDataJson = JSON.parseObject(roleData);
//            String rolecard = roleDataJson.getString("rolecard");
//            JSONObject rolelistJson = JSON.parseObject(rolecard);
//            skinMap.put("gameMvp", rolelistJson.getString("mvpNum"));
//            skinMap.put("heroNum", rolelistJson.getString("heroNum"));
//            skinMap.put("skinNum", rolelistJson.getString("skinNum"));
//            skinMap.put("areaId", rolelistJson.getString("areaId"));
//            skinMap.put("totalCount", rolelistJson.getString("totalCount"));
//            skinMap.put("mvpNum", rolelistJson.getString("mvpNum"));
//            skinMap.put("vipLevel", rolelistJson.getString("nobilityLevel"));
//            skinMap.put("yingdiIdsd", yingdiId);
//            //段位
//            skinMap.put("jobName", rolelistJson.getString("jobName"));
//
//            String fiveStar = rolelistJson.getString("fiveStar");
//            JSONArray objects = JSON.parseArray(fiveStar);
//            for (Object object : objects) {
//                String string = JSON.toJSONString(object);
//                JSONObject jsonObject = JSON.parseObject(string);
//                String scale = jsonObject.getString("title");
//                if ("战斗力".equals(scale)) {
//                    skinMap.put("zhandouli", jsonObject.getString("value"));
//                }
//            }
//        } else {
//            settoken(sysDictDataList);
//        }
//        String url = "https://ssl.kohsocialapp.qq.com:10001/play/h5getheroskinlist";
//
//
//        Map<String, Object> params = new HashMap<>();
//        params.put("openId", "oFhrws8OqdftI_7819rEA4eYgMsU");
//        params.put("userId", userId);
//        params.put("token", token);
//        params.put("cClientVersionName", "6.73.106");
//        params.put("cSystemVersionCode", "23");
//        params.put("uniqueRoleId", roleId);
//
//        List<String> rongyaoList = new ArrayList<>();
//        List<JSONObject> rongyaoListJson = new ArrayList<>();
//        List<String> rongyaoListStr = new ArrayList<>();
//
//        String s = HttpUtils.doPostForm(url, params, head);
//        System.out.println(s);
//        //内测
//        List<JSONObject> neiceiJson = new ArrayList<>();
//        List<String> neiceName = new ArrayList<>();
//        //典藏
//        List<JSONObject> diancangJson = new ArrayList<>();
//        List<String> diancangName = new ArrayList<>();
//        //限定
//        List<JSONObject> xiandingJson = new ArrayList<>();
//        List<String> xiandingName = new ArrayList<>();
//        //星元
//        List<JSONObject> xingyuanJson = new ArrayList<>();
//        List<String> xingyuanName = new ArrayList<>();
//        //传说
//        List<JSONObject> chuanshuoJson = new ArrayList<>();
//        List<String> chuanshuoName = new ArrayList<>();
//        //史诗
//        List<JSONObject> shishiJson = new ArrayList<>();
//        List<String> shishiName = new ArrayList<>();
//
//        List<String> goodSkinName = new ArrayList<>();
//
//        //获取皮肤类型列表
//        JSONObject jsonObject = JSON.parseObject(s);
//        if ("0".equals(jsonObject.getString("result"))) {
//            JSONObject data = jsonObject.getJSONObject("data");
//            JSONObject skinCountInfo = data.getJSONObject("skinCountInfo");
//            String skinTypeList = skinCountInfo.getString("skinTypeList");
//            JSONArray objects = JSON.parseArray(skinTypeList);
//
//
//            Integer skinIds[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26
//                    , 27, 28, 29, 30, 31, 32, 33,
//                    34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45};
//            Integer rongyao[] = {1};
//            Integer remen[] = {1, 3, 4, 17, 18, 20, 23, 24, 26, 30, 31, 32, 33, 34, 35, 41, 45, 43, 42};
//            Integer xianding[] = {4, 7, 8, 9, 10, 11, 17, 18, 20, 21, 23, 24, 30, 31, 32, 35, 45};
//            Integer chuanshuo[] = {2};
//            Integer shishi[] = {3};
//
//
//            //首先拿到需要拼图的皮肤类型
//            //查找对应的皮肤id
//            //筛选已有的皮肤
//            //返回信息
//
//            //总皮肤列表
//            String heroSkinConfList = data.getString("heroSkinConfList");
//
//            //传说数量
//            List<String> chuanshuoList = new ArrayList<>();
//
//            List<String> shishiList = new ArrayList<>();
//
//
//            List<String> classIds = new ArrayList<>();
//            List<String> remenIds = new ArrayList<>();
//            List<String> xiandingIds = new ArrayList<>();
//
//
//            JSONObject heroSkinConfJson = JSON.parseObject(heroSkinConfList);
//            for (String s1 : heroSkinConfJson.keySet()) {
//                String string = heroSkinConfJson.getString(s1);
//                JSONObject parseObject = JSON.parseObject(string);
//                String classType = parseObject.getString("classType");
//                JSONArray classObjArr = JSON.parseArray(classType);
//
//
//                if (CollectionUtils.isNotEmpty(classObjArr)) {
//                    for (Object o : classObjArr) {
//                        if (Arrays.asList(skinIds).contains(Integer.valueOf(o.toString()))) {
//                            classIds.add(s1);
//                        }
//                        if (Arrays.asList(remen).contains(Integer.valueOf(o.toString()))) {
//                            remenIds.add(s1);
//                        }
//                        if (Arrays.asList(xianding).contains(Integer.valueOf(o.toString()))) {
//                            xiandingIds.add(s1);
//                        }
//                        if (Arrays.asList(chuanshuo).contains(Integer.valueOf(o.toString()))) {
//                            chuanshuoList.add(s1);
//                        }
//                        if (Arrays.asList(shishi).contains(Integer.valueOf(o.toString()))) {
//                            shishiList.add(s1);
//                        }
//                        if (Arrays.asList(rongyao).contains(Integer.valueOf(o.toString()))) {
//                            rongyaoList.add(s1);
//                        }
//                    }
//                }
//            }
//            Integer chuanshuoCount = 0;
//            Integer shishiCount = 0;
//            int neiceCount = 0;
//
//            //皮肤列表
//            String heroSkinList = data.getString("heroSkinList");
//            JSONArray heroSkinListJson = JSON.parseArray(heroSkinList);
//
//            //稀有英雄
//            String[] xiyouhero = {"136"};
//            String[] neice = {"155"};
//            String heroList = data.getString("heroList");
//            JSONObject heroListJson = JSON.parseObject(heroList);
//            for (String s1 : heroListJson.keySet()) {
//                if (Arrays.asList(xiyouhero).contains(s1)) {
//                    if ("136".equals(s1)) {
//                        diancangName.add("武则天");
//                        rongyaoListStr.add("武则天");
//                        JSONObject ry = new JSONObject();
//                        ry.put("szTitle", "武则天");
//                        rongyaoListJson.add(ry);
//                    }
//                }
//            }
//
//            String[] neiceSkin = {"15501301", "11003", "11503"};
//            List<JSONObject> resultJsonObj = new ArrayList<>();
//            List<JSONObject> remenSjson = new ArrayList<>();
//            for (Object o : heroSkinListJson) {
//                JSONObject skinObj = JSON.parseObject(JSON.toJSONString(o));
//                String skinId = skinObj.getString("skinId");
//                String szTitle = skinObj.getString("szTitle");
//
//                for (String neiceid : neiceSkin) {
//                    if (skinId.equals(neiceid)) {
//                        neiceName.add(szTitle);
//                        neiceiJson.add(skinObj);
//                    }
//                }
//
//                for (String classid : classIds) {
//                    if (skinId.equals(classid)) {
//                        resultJsonObj.add(skinObj);
//                    }
//                }
//                for (String ry : rongyaoList) {
//                    if (skinId.equals(ry)) {
//                        diancangName.add(szTitle);
//                        diancangJson.add(skinObj);
//                        rongyaoListStr.add(szTitle);
//                    }
//                }
//                for (String chuanshuo1 : chuanshuoList) {
//                    if (skinId.equals(chuanshuo1)) {
//                        chuanshuoCount++;
//                        chuanshuoName.add(szTitle);
//                        chuanshuoJson.add(skinObj);
//                    }
//                }
//                for (String shishi1 : shishiList) {
//                    if (skinId.equals(shishi1)) {
//                        shishiCount++;
//                        shishiName.add(szTitle);
//                        shishiJson.add(skinObj);
//                    }
//                }
//                for (String remenId1 : remenIds) {
//                    if (skinId.equals(remenId1)) {
//                        remenSjson.add(skinObj);
//                    }
//                }
//                for (String xiandingId : xiandingIds) {
//                    if (skinId.equals(xiandingId)) {
//                        xiandingName.add(szTitle);
//                        xiandingJson.add(skinObj);
//                    }
//                }
//            }
//
//            Set<JSONObject> imgSet = new HashSet();
//            imgSet.addAll(resultJsonObj);
//
//            resultMap.put("skinList", imgSet);
//
//            LinkedHashSet<String> xiandingNameSet = new LinkedHashSet<String>(xiandingName.size());
//            xiandingNameSet.addAll(xiandingName);
//
//            LinkedHashSet<String> diancangNameSet = new LinkedHashSet<String>(diancangName.size());
//            diancangNameSet.addAll(diancangName);
//
//            LinkedHashSet<String> neiceNameSet = new LinkedHashSet<String>(neiceName.size());
//            neiceNameSet.addAll(neiceName);
//
//            LinkedHashSet<String> chuanshuoNameSet = new LinkedHashSet<String>(chuanshuoName.size());
//            chuanshuoNameSet.addAll(chuanshuoName);
//
//
//            LinkedHashSet<String> shishiNameSet = new LinkedHashSet<String>(shishiName.size());
//            shishiNameSet.addAll(shishiName);
//
//
//            for (String xiand : xiandingNameSet) {
//                chuanshuoNameSet.remove(xiand);
//                shishiNameSet.remove(xiand);
//                neiceNameSet.remove(xiand);
//                diancangNameSet.remove(xiand);
//            }
//
//
//            goodSkinName.addAll(diancangName);
//            goodSkinName.addAll(neiceName);
//            goodSkinName.addAll(xiandingName);
//            goodSkinName.addAll(chuanshuoName);
//            goodSkinName.addAll(shishiName);
//
//            List<String> remenList = new ArrayList<>();
//            List<SysDictData> hotWord = sysDictDataMapper.selectDictDataByType("wzryHot");
//            for (SysDictData sysDictData : hotWord) {
//                for (String skin : goodSkinName) {
//                    if (Objects.equals(skin, sysDictData.getDictLabel())) {
//                        remenList.add(skin);
//                    }
//                }
//            }
//            for (String rm : remenList) {
//                chuanshuoNameSet.remove(rm);
//                shishiNameSet.remove(rm);
//                neiceNameSet.remove(rm);
//                diancangNameSet.remove(rm);
//            }
//
//            LinkedHashSet<String> remenListSet = new LinkedHashSet<String>(remenList.size());
//            remenListSet.addAll(remenList);
//
//
//            String join =
//                    "【热门皮肤】: " + StringUtils.join(remenListSet, " ") + "--" +
//                            "【限定皮肤】: " + StringUtils.join(xiandingNameSet, " ") + "--" +
//                            "【荣耀典藏】: " + StringUtils.join(diancangNameSet, " ") + "--" +
//                            "【内  测】: " + StringUtils.join(neiceNameSet, " ") + "--" +
//                            "【传说皮肤】: " + StringUtils.join(chuanshuoNameSet, " ") + "--" +
//                            "【史诗皮肤】: " + StringUtils.join(shishiNameSet, " ") + "--";
//
//            String areaId = MapUtils.getString(skinMap, "areaId");
//
////            if ("1".equals(areaId)) {
////                areaId = "安卓Q";
////            } else if ("2".equals(areaId)) {
////                areaId = "苹果Q";
////            } else if ("3".equals(areaId)) {
////                areaId = "安卓WX";
////            } else if ("4".equals(areaId)) {
////                areaId = "苹果WX";
////            }
//
//            if ("1".equals(areaId)) {
//                areaId = "安卓Q";
//
//                skinMap.put("systemId", 38241);
//                skinMap.put("carrierId", 38243);
//                skinMap.put("groupId", 38246);
//                skinMap.put("serverId", 41683);
//
//            } else if ("2".equals(areaId)) {
//                areaId = "苹果Q";
//                skinMap.put("systemId", 38240);
//
//                skinMap.put("carrierId", 38243);
//                skinMap.put("groupId", 38246);
//                skinMap.put("serverId", 41683);
//
//
//            } else if ("3".equals(areaId)) {
//
//                areaId = "安卓WX";
//                skinMap.put("systemId", 38241);
//
//                skinMap.put("carrierId", 38244);
//                skinMap.put("groupId", 38248);
//                skinMap.put("serverId", 41684);
//
//            } else if ("4".equals(areaId)) {
//                areaId = "苹果WX";
//
//                skinMap.put("systemId", 38240);
//
//                skinMap.put("carrierId", 38244);
//                skinMap.put("groupId", 38248);
//                skinMap.put("serverId", 41684);
//            }
//
//            skinMap.put("areaName", areaId);
//
//            String des = "大区:" + areaId + " 营地：" + yingdiId +
//                    " 贵族等级:" + MapUtils.getString(skinMap, "vipLevel") + " " + join;
//
//            skinMap.put("ppxiangqing", des);
//
//            LinkedHashSet<String> set = new LinkedHashSet<String>(goodSkinName.size());
//            set.addAll(goodSkinName);
//            goodSkinName.clear();
//            goodSkinName.addAll(set);
//            if (goodSkinName.size() > 48) {
//                goodSkinName = goodSkinName.subList(0, 48);
//            }
//
//            resultMap.put("skinMap", skinMap);
//            resultMap.put("goodSkinName", goodSkinName);
//
//            List<JSONObject> listJson = new ArrayList<>();
//            listJson.addAll(diancangJson);
//            listJson.addAll(neiceiJson);
//            listJson.addAll(xiandingJson);
//            listJson.addAll(chuanshuoJson);
//            listJson.addAll(shishiJson);
//            listJson.addAll(rongyaoListJson);
//            List<JSONObject> resultJson = new ArrayList<>();
//            List<SysDictData> wzryNick = sysDictDataMapper.selectDictDataByType("wzryNick");
//            for (SysDictData sysDictData : wzryNick) {
//                for (JSONObject object : listJson) {
//                    String szHeroAlias = object.getString("szDesc");
//                    if (Objects.equals(szHeroAlias, sysDictData.getDictLabel())) {
//                        object.put("szTitle", sysDictData.getDictValue());
//                    }
//                    resultJson.add(object);
//                }
//            }
//
//            LinkedHashSet<JSONObject> set1 = new LinkedHashSet<JSONObject>(resultJson.size());
//            set1.addAll(resultJson);
//            resultJson.clear();
//            resultJson.addAll(set1);
//            resultMap.put("listJson", resultJson);
//
//            Integer rongyaoCount = 0;
//
//
//            for (JSONObject object : resultJson) {
//                String skinId = object.getString("skinId");
//                String iClass = object.getString("iClass");
//                for (String s1 : heroSkinConfJson.keySet()) {
//                    if (Objects.equals(skinId, s1)) {
//                        String string = heroSkinConfJson.getString(s1);
//                        JSONObject parseObject = JSON.parseObject(string);
//                        String classType = parseObject.getString("classType");
//                        JSONArray classObjArr = JSON.parseArray(classType);
//
//                        if (CollectionUtils.isNotEmpty(classObjArr)) {
//                            List<Integer> integers = JSON.parseArray(classType, Integer.class);
//                            if (integers.contains(1) && Objects.nonNull(iClass)) {
//                                rongyaoCount++;
//                            }
//
//                        }
//                    }
//                }
//            }
//
//
//            skinMap.put("shuijingnum", rongyaoCount);
//            skinMap.put("rongyaoCount", rongyaoCount);
//            addGengerCount();
//
//        }
//        return resultMap;
//    }

    private void settoken(List<SysDictData> sysDictDataList) {
        SysDictData sysDictData = sysDictDataList.get(0);
        SysDictData noMax = sysDictDataList.stream().max(Comparator.comparing(SysDictData::getDictSort)).get();
        Long newsort = noMax.getDictSort() + 1l;
        sysDictData.setDictSort(newsort);
        sysDictDataMapper.updateDictData(sysDictData);
    }

    private void addGengerCount() {
        List<SysDictData> imgGengerCount = sysDictDataMapper.selectDictDataByType("imgGengerCount");
        for (SysDictData sysDictData : imgGengerCount) {
            if (Objects.equals(sysDictData.getDictLabel(), "wzry")) {
                String dictValue = sysDictData.getDictValue();
                int valueCOunt = Integer.valueOf(dictValue);
                valueCOunt++;
                sysDictData.setDictValue(String.valueOf(valueCOunt));
                sysDictDataMapper.updateDictData(sysDictData);
            }
        }

    }

//    @Override
//    public Map<String, Object> genTitleBack(Map<String, Object> titleParams) {
//
//        String yingdiId = MapUtils.getString(titleParams, "campId");
//        String roleId = MapUtils.getString(titleParams, "roleId");
//
//        Map<String, Object> resultMap = new HashMap<>();
//
//        Map<String, Object> skinMap = new HashMap<>();
//
//        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("yingdiToken");
//        String token = sysDictDataList.get(0).getDictValue();
//        String userId = sysDictDataList.get(0).getDictLabel();
//
//        String roleUrl = "https://ssl.kohsocialapp.qq.com:10001/game/battleprofile";
//
//
//        Map<String, Object> paramsRoleList = new HashMap<>();
//        paramsRoleList.put("friendUserId", yingdiId);
//        paramsRoleList.put("roleId", roleId);
//        paramsRoleList.put("gameId", "20001");
//        paramsRoleList.put("token", token);
//        paramsRoleList.put("userId", userId);
//        paramsRoleList.put("cClientVersionName", "6.72.301");
//
//        Map<String, Object> head = new HashMap<>();
//
//        head.put("content-type", "application/x-www-form-urlencoded");
//
//
//        String roleList = HttpUtils.doPostForm(roleUrl, paramsRoleList, null);
//        log.info(roleList);
//
//        JSONObject roleJson = JSON.parseObject(roleList);
//        String result = roleJson.getString("result");
//        if ("0".equals(result)) {
//            String roleData = roleJson.getString("data");
//            JSONObject roleDataJson = JSON.parseObject(roleData);
//            String rolecard = roleDataJson.getString("rolecard");
//            JSONObject rolelistJson = JSON.parseObject(rolecard);
//            skinMap.put("gameMvp", rolelistJson.getString("mvpNum"));
//            skinMap.put("heroNum", rolelistJson.getString("heroNum"));
//            skinMap.put("skinNum", rolelistJson.getString("skinNum"));
//            skinMap.put("areaId", rolelistJson.getString("areaId"));
//            skinMap.put("totalCount", rolelistJson.getString("totalCount"));
//            skinMap.put("mvpNum", rolelistJson.getString("mvpNum"));
//            skinMap.put("vipLevel", rolelistJson.getString("nobilityLevel"));
//            skinMap.put("yingdiIdsd", yingdiId);
//            //
//            skinMap.put("jobName", rolelistJson.getString("jobName"));
//
//            String fiveStar = rolelistJson.getString("fiveStar");
//            JSONArray objects = JSON.parseArray(fiveStar);
//            for (Object object : objects) {
//                String string = JSON.toJSONString(object);
//                JSONObject jsonObject = JSON.parseObject(string);
//                String scale = jsonObject.getString("title");
//                if ("战斗力".equals(scale)) {
//                    skinMap.put("zhandouli", jsonObject.getString("value"));
//                }
//            }
//        } else {
//            SysDictData sysDictData = sysDictDataList.get(0);
//            SysDictData noMax = sysDictDataList.stream().max(Comparator.comparing(SysDictData::getDictSort)).get();
//            Long newsort = noMax.getDictSort() + 1l;
//            sysDictData.setDictSort(newsort);
//            sysDictDataMapper.updateDictData(sysDictData);
//        }
//        String url = "https://ssl.kohsocialapp.qq.com:10001/play/h5getheroskinlist";
//
//
//        Map<String, Object> params = new HashMap<>();
//        params.put("openId", "oFhrws8OqdftI_7819rEA4eYgMsU");
//        params.put("userId", userId);
//        params.put("token", token);
//        params.put("cClientVersionName", "6.73.106");
//        params.put("cSystemVersionCode", "23");
//        params.put("uniqueRoleId", roleId);
//
//
//        List<String> rongyaoList = new ArrayList<>();
//        List<JSONObject> rongyaoListJson = new ArrayList<>();
//        List<String> rongyaoListStr = new ArrayList<>();
//
//        String s = HttpUtils.doPostForm(url, params, head);
//        System.out.println(s);
//        //内测
//        List<JSONObject> neiceiJson = new ArrayList<>();
//        List<String> neiceName = new ArrayList<>();
//        //典藏
//        List<JSONObject> diancangJson = new ArrayList<>();
//        List<String> diancangName = new ArrayList<>();
//        //限定
//        List<JSONObject> xiandingJson = new ArrayList<>();
//        List<String> xiandingName = new ArrayList<>();
//        //星元
//        List<JSONObject> xingyuanJson = new ArrayList<>();
//        List<String> xingyuanName = new ArrayList<>();
//        //传说
//        List<JSONObject> chuanshuoJson = new ArrayList<>();
//        List<String> chuanshuoName = new ArrayList<>();
//        //史诗
//        List<JSONObject> shishiJson = new ArrayList<>();
//        List<String> shishiName = new ArrayList<>();
//
//        List<String> goodSkinName = new ArrayList<>();
//
//        //获取皮肤类型列表
//        JSONObject jsonObject = JSON.parseObject(s);
//        if ("0".equals(jsonObject.getString("result"))) {
//            JSONObject data = jsonObject.getJSONObject("data");
//            JSONObject skinCountInfo = data.getJSONObject("skinCountInfo");
//            String skinTypeList = skinCountInfo.getString("skinTypeList");
//            JSONArray objects = JSON.parseArray(skinTypeList);
//
//
//            Integer skinIds[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
//            26, 27, 28, 29, 30, 31, 32, 33,
//                    34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45};
//            Integer rongyao[] = {1};
//            Integer remen[] = {1, 3, 4, 17, 18, 20, 23, 24, 26, 30, 31, 32, 33, 34, 35, 41, 45, 43, 42};
//            Integer xianding[] = {4, 7, 8, 9, 10, 11, 17, 18, 20, 21, 23, 24, 30, 31, 32, 35, 45};
//            Integer chuanshuo[] = {2};
//            Integer shishi[] = {3};
//
//            //首先拿到需要拼图的皮肤类型
//            //查找对应的皮肤id
//            //筛选已有的皮肤
//            //返回信息
//
//            //总皮肤列表
//            String heroSkinConfList = data.getString("heroSkinConfList");
//
//            //传说数量
//            List<String> chuanshuoList = new ArrayList<>();
//
//            List<String> shishiList = new ArrayList<>();
//
//
//            List<String> classIds = new ArrayList<>();
//            List<String> remenIds = new ArrayList<>();
//            List<String> xiandingIds = new ArrayList<>();
//
//            JSONObject heroSkinConfJson = JSON.parseObject(heroSkinConfList);
//            for (String s1 : heroSkinConfJson.keySet()) {
//                String string = heroSkinConfJson.getString(s1);
//                JSONObject parseObject = JSON.parseObject(string);
//                String classType = parseObject.getString("classType");
//                JSONArray classObjArr = JSON.parseArray(classType);
//
//                if (CollectionUtils.isNotEmpty(classObjArr)) {
//                    for (Object o : classObjArr) {
//                        if (Arrays.asList(skinIds).contains(Integer.valueOf(o.toString()))) {
//                            classIds.add(s1);
//                        }
//                        if (Arrays.asList(remen).contains(Integer.valueOf(o.toString()))) {
//                            remenIds.add(s1);
//                        }
//                        if (Arrays.asList(xianding).contains(Integer.valueOf(o.toString()))) {
//                            xiandingIds.add(s1);
//                        }
//                        if (Arrays.asList(chuanshuo).contains(Integer.valueOf(o.toString()))) {
//                            chuanshuoList.add(s1);
//                        }
//                        if (Arrays.asList(shishi).contains(Integer.valueOf(o.toString()))) {
//                            shishiList.add(s1);
//                        }
//                        if (Arrays.asList(rongyao).contains(Integer.valueOf(o.toString()))) {
//                            rongyaoList.add(s1);
//                        }
//                    }
//                }
//            }
//            Integer chuanshuoCount = 0;
//            Integer shishiCount = 0;
//            int rongyaoCount = 0;
//            int neiceCount = 0;
//
//            //皮肤列表
//            String heroSkinList = data.getString("heroSkinList");
//            JSONArray heroSkinListJson = JSON.parseArray(heroSkinList);
//
//            //稀有英雄
//            String[] xiyouhero = {"136"};
//            String[] neice = {"155"};
//            String heroList = data.getString("heroList");
//            JSONObject heroListJson = JSON.parseObject(heroList);
//            for (String s1 : heroListJson.keySet()) {
//                if (Arrays.asList(xiyouhero).contains(s1)) {
//                    if ("136".equals(s1)) {
//                        diancangName.add("武则天");
//                        rongyaoListStr.add("武则天");
//                        JSONObject ry = new JSONObject();
//                        ry.put("szTitle", "武则天");
//                        rongyaoListJson.add(ry);
//                    }
//                }
//            }
//
//            String[] neiceSkin = {"15501301", "11003", "11503"};
//            List<JSONObject> resultJsonObj = new ArrayList<>();
//            List<JSONObject> remenSjson = new ArrayList<>();
//            for (Object o : heroSkinListJson) {
//                JSONObject skinObj = JSON.parseObject(JSON.toJSONString(o));
//                String skinId = skinObj.getString("skinId");
//                String szTitle = skinObj.getString("szTitle");
//                String iClass = skinObj.getString("iClass");
//
//                for (String neiceid : neiceSkin) {
//                    if (skinId.equals(neiceid)) {
//                        neiceName.add(szTitle);
//                        neiceiJson.add(skinObj);
//                    }
//                }
//
//                for (String classid : classIds) {
//                    if (skinId.equals(classid)) {
//                        resultJsonObj.add(skinObj);
//                    }
//                }
//                for (String ry : rongyaoList) {
//                    if (skinId.equals(ry)) {
//                        diancangName.add(szTitle);
//                        diancangJson.add(skinObj);
//                        rongyaoListStr.add(szTitle);
//                    }
//                }
//                for (String chuanshuo1 : chuanshuoList) {
//                    if (skinId.equals(chuanshuo1)) {
//                        chuanshuoCount++;
//                        chuanshuoName.add(szTitle);
//                        chuanshuoJson.add(skinObj);
//                    }
//                }
//                for (String shishi1 : shishiList) {
//                    if (skinId.equals(shishi1)) {
//                        shishiCount++;
//                        shishiName.add(szTitle);
//                        shishiJson.add(skinObj);
//                    }
//                }
//                for (String remenId1 : remenIds) {
//                    if (skinId.equals(remenId1)) {
//                        remenSjson.add(skinObj);
//                    }
//                }
//                for (String xiandingId : xiandingIds) {
//                    if (skinId.equals(xiandingId)) {
//                        xiandingName.add(szTitle);
//                        xiandingJson.add(skinObj);
//                    }
//                }
//            }
//
//            Set<JSONObject> imgSet = new HashSet();
//            imgSet.addAll(resultJsonObj);
//
//            resultMap.put("skinList", imgSet);
//            List<String> szTitle = imgSet.stream().map(i -> i.getString("szTitle")).collect(Collectors.toList());
//
//            LinkedHashSet<String> xiandingNameSet = new LinkedHashSet<String>(xiandingName.size());
//            xiandingNameSet.addAll(xiandingName);
//
//            LinkedHashSet<String> diancangNameSet = new LinkedHashSet<String>(diancangName.size());
//            diancangNameSet.addAll(diancangName);
//
//            LinkedHashSet<String> neiceNameSet = new LinkedHashSet<String>(neiceName.size());
//            neiceNameSet.addAll(neiceName);
//
//            LinkedHashSet<String> chuanshuoNameSet = new LinkedHashSet<String>(chuanshuoName.size());
//            chuanshuoNameSet.addAll(chuanshuoName);
//
//
//            LinkedHashSet<String> shishiNameSet = new LinkedHashSet<String>(shishiName.size());
//            shishiNameSet.addAll(shishiName);
//
//
//            for (String xiand : xiandingNameSet) {
//                chuanshuoNameSet.remove(xiand);
//                shishiNameSet.remove(xiand);
//                neiceNameSet.remove(xiand);
//                diancangNameSet.remove(xiand);
//            }
//
//
//            goodSkinName.addAll(diancangName);
//            goodSkinName.addAll(neiceName);
//            goodSkinName.addAll(xiandingName);
//            goodSkinName.addAll(chuanshuoName);
//            goodSkinName.addAll(shishiName);
//
//            List<String> remenList = new ArrayList<>();
//            List<SysDictData> hotWord = sysDictDataMapper.selectDictDataByType("wzryHot");
//            for (SysDictData sysDictData : hotWord) {
//                for (String skin : goodSkinName) {
//                    if (Objects.equals(skin, sysDictData.getDictLabel())) {
//                        remenList.add(skin);
//                    }
//                }
//            }
//            for (String rm : remenList) {
//                chuanshuoNameSet.remove(rm);
//                shishiNameSet.remove(rm);
//                neiceNameSet.remove(rm);
//                diancangNameSet.remove(rm);
//            }
//
//            LinkedHashSet<String> remenListSet = new LinkedHashSet<String>(remenList.size());
//            remenListSet.addAll(remenList);
//
//
//            String join =
//                    "【热门皮肤】: " + StringUtils.join(remenListSet, " ") + "--" +
//                            "【限定皮肤】: " + StringUtils.join(xiandingNameSet, " ") + "--" +
//                            "【荣耀典藏】: " + StringUtils.join(diancangNameSet, " ") + "--" +
//                            "【内  测】: " + StringUtils.join(neiceNameSet, " ") + "--" +
//                            "【传说皮肤】: " + StringUtils.join(chuanshuoNameSet, " ") + "--" +
//                            "【史诗皮肤】: " + StringUtils.join(shishiNameSet, " ") + "--";
//
//            String areaId = MapUtils.getString(skinMap, "areaId");
//
//            if ("1".equals(areaId)) {
//                areaId = "安卓Q";
//
//                skinMap.put("systemId",38241);
//                skinMap.put("carrierId",38243);
//                skinMap.put("groupId",38246);
//                skinMap.put("serverId",41683);
//
//            } else if ("2".equals(areaId)) {
//                areaId = "苹果Q";
//                skinMap.put("systemId",38240);
//
//                skinMap.put("carrierId",38243);
//                skinMap.put("groupId",38246);
//                skinMap.put("serverId",41683);
//
//
//            } else if ("3".equals(areaId)) {
//
//                areaId = "安卓WX";
//                skinMap.put("systemId",38241);
//
//                skinMap.put("carrierId",38244);
//                skinMap.put("groupId",38248);
//                skinMap.put("serverId",41684);
//
//            } else if ("4".equals(areaId)) {
//                areaId = "苹果WX";
//
//                skinMap.put("systemId",38240);
//
//                skinMap.put("carrierId",38244);
//                skinMap.put("groupId",38248);
//                skinMap.put("serverId",41684);
//            }
//
//            skinMap.put("areaName", areaId);
//
//            String des = "大区:" + areaId + " 营地：" + yingdiId +
//                    " 贵族等级:" + MapUtils.getString(skinMap, "vipLevel") + " " + join;
//
//            skinMap.put("ppxiangqing", des);
//
//            LinkedHashSet<String> set = new LinkedHashSet<String>(goodSkinName.size());
//            set.addAll(goodSkinName);
//            goodSkinName.clear();
//            goodSkinName.addAll(set);
//            if (goodSkinName.size() > 48) {
//                goodSkinName = goodSkinName.subList(0, 48);
//            }
//
//            resultMap.put("skinMap", skinMap);
//            resultMap.put("goodSkinName", goodSkinName);
//        }
//
//        List<JSONObject> listJson = new ArrayList<>();
//        listJson.addAll(diancangJson);
//        listJson.addAll(neiceiJson);
//        listJson.addAll(xiandingJson);
//        listJson.addAll(chuanshuoJson);
//        listJson.addAll(shishiJson);
//        listJson.addAll(rongyaoListJson);
//        int rongyaoCount = 0;
//        List<JSONObject> resultJson = new ArrayList<>();
//        List<SysDictData> wzryNick = sysDictDataMapper.selectDictDataByType("wzryNick");
//        for (SysDictData sysDictData : wzryNick) {
//            for (JSONObject object : listJson) {
//                String szHeroAlias = object.getString("szDesc");
//                if (Objects.equals(szHeroAlias, sysDictData.getDictLabel())) {
//                    object.put("szTitle", sysDictData.getDictValue());
//                }
//                resultJson.add(object);
//            }
//        }
//
//        LinkedHashSet<JSONObject> set = new LinkedHashSet<JSONObject>(resultJson.size());
//        set.addAll(resultJson);
//        resultJson.clear();
//        resultJson.addAll(set);
//        resultMap.put("listJson", resultJson);
//
//        for (JSONObject object : resultJson) {
//            String iClass = object.getString("iClass");
//            if (Objects.equals("0", iClass)) {
//                rongyaoCount++;
//            }
//        }
//
//        skinMap.put("shuijingnum", rongyaoCount);
//        skinMap.put("rongyaoCount", rongyaoCount);
//
//        List<SysDictData> imgGengerCount = sysDictDataMapper.selectDictDataByType("imgGengerCount");
//        for (SysDictData sysDictData : imgGengerCount) {
//            if (Objects.equals(sysDictData.getDictLabel(), "wzry")) {
//                String dictValue = sysDictData.getDictValue();
//                int valueCOunt = Integer.valueOf(dictValue);
//                valueCOunt++;
//                sysDictData.setDictValue(String.valueOf(valueCOunt));
//                sysDictDataMapper.updateDictData(sysDictData);
//            }
//        }
//        return resultMap;
//    }


    @Override
    public Map<String, Object> gengerImge(Map<String, Object> params) {

        log.info("params = {}", JSON.toJSONString(params));

        List<JSONObject> listJson = new ArrayList<>();

        String textImg = MapUtils.getString(params, "textImg");
        String detailsImg = MapUtils.getString(params, "detailsImg");

        String xingyuan = MapUtils.getString(params, "xingyuan");
        List<Long> longs = JSONObject.parseArray(xingyuan, Long.class);
        String xingyuanStr = "";
        if (StringUtils.isNotEmpty(longs)) {
            for (Long s : longs) {
                SysDictData sysDictData = sysDictDataMapper.selectDictDataById(s);
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("szSmallIcon", sysDictData.getRemark());
                jsonObject.put("szTitle", sysDictData.getDictLabel());
                listJson.add(jsonObject);
                xingyuanStr = xingyuanStr + sysDictData.getDictLabel() + " ";
            }
//            List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("wzryRare");
//            for (SysDictData sysDictData : sysDictDataList) {
//                for (String code : split) {
//                    if (sysDictData.getDictCode().toString().equals(code)){
//                        JSONObject jsonObject = new JSONObject();
//                        jsonObject.put("szSmallIcon",sysDictData.getRemark());
//                        jsonObject.put("szTitle",sysDictData.getDictLabel());
//                        listJson.add(jsonObject);
//                        xingyuanStr = xingyuanStr + sysDictData.getDictLabel() + " ";
//                    }
//                }
//            }

        }

        Map<String, Object> result = new HashMap<>();
        Map<String, Object> stringObjectMap = genTitleBack(params);
        //贵族积分
        String nobNum = MapUtils.getString(params, "nobNum");
        //五级铭文
        String inscriptions = MapUtils.getString(params, "inscriptions");
        //王者印记
        String yinji = MapUtils.getString(params, "yinji");
        //实名
        String shiming = MapUtils.getString(params, "shiming");
        //紫晶
        String zijing = MapUtils.getString(params, "zijing");
        String vipLevel = MapUtils.getString(params, "vipLevel");

        //幸运值
        String xingyung = MapUtils.getString(params, "xingyung");
        String shengbiao = MapUtils.getString(params, "shengbiao");
        //选择皮肤截图
        String pifiids = MapUtils.getString(params, "pifiids");
        String goodSkinName = MapUtils.getString(params, "goodSkins");
        if (Objects.equals("1", shiming)) {
            shiming = "可实名";
        } else {
            shiming = "包人脸";
        }
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(stringObjectMap));
        JSONObject skinMap = jsonObject.getJSONObject("skinMap");

        String ppxiangqing = skinMap.getString("ppxiangqing");
//        String ppxiangqing = MapUtils.getString(params, "ppxiangqing");
        String pp = null;
        if (StringUtils.isNotEmpty(xingyuan)) {
            pp = "贵族积分:" + nobNum + " 五级铭文:" + inscriptions + " 王者印记:" + yinji + " 实名: " + shiming + " " + ppxiangqing + "  【星元皮肤】: " + xingyuanStr;
        } else {
            pp = "贵族积分:" + nobNum + " 五级铭文:" + inscriptions + " 王者印记:" + yinji + " 实名: " + shiming + " " + ppxiangqing;
        }
        result.put("ppxiangqing", pp);

        if (Objects.equals("1", textImg)) {

//            String goodSkinName = jsonObject.getString("goodSkinName");
//            JSONArray objects = JSON.parseArray(goodSkinName);
//            goodSkinName = StringUtils.join(objects, " ");
            if (StringUtils.isNotEmpty(pifiids)) {
                String[] split = pifiids.split(",");
                Attribute attribute = new Attribute();
                attribute.setIds(Arrays.asList(split));
                List<Attribute> attributeList = attributeMapper.selectAttributeList(attribute);
                attributeList =
                        attributeList.stream().filter(im -> StringUtils.isNotEmpty(im.getImgUrl())).collect(Collectors.toList());
                Map<String, Object> imgParams = new HashMap<>();
                String titleName = "区服 " + MapUtils.getString(skinMap, "areaName") + "(贵族 V" + vipLevel + ")";
                imgParams.put("titleName", titleName);
                imgParams.put("title1", "英雄数量 ");
                imgParams.put("title2", "皮肤数量 ");
                imgParams.put("title3", "贵族等级 ");
                imgParams.put("title4", "水晶数量 ");
                imgParams.put("title5", "贵族积分 ");
                imgParams.put("title6", "五级铭文 ");
                imgParams.put("title7", "王者印记 ");
                imgParams.put("title8", "实名状态 ");
                imgParams.put("title9", "紫晶币 ");
                imgParams.put("title10", "幸运值 ");

                imgParams.put("cotent1", MapUtils.getString(skinMap, "heroNum"));
                imgParams.put("cotent2", MapUtils.getString(skinMap, "skinNum"));
                imgParams.put("cotent3", "V" + vipLevel);
                imgParams.put("cotent4", MapUtils.getString(skinMap, "rongyaoCount"));
                imgParams.put("cotent5", nobNum);
                imgParams.put("cotent6", inscriptions);
                imgParams.put("cotent7", yinji);
                imgParams.put("cotent8", shiming);
                imgParams.put("cotent9", zijing);
                imgParams.put("cotent10", xingyung);
                imgParams.put("des1Title", shengbiao);

                String remake =
                        "MVP次数 " + MapUtils.getString(skinMap, "mvpNum") + " 游戏场次" + MapUtils.getString(skinMap,
                                "totalCount") +
                                " 战斗力 " + MapUtils.getString(skinMap, "zhandouli");
                imgParams.put("remake", remake);

                imgParams.put("strContent1", JSONObject.toJSONString(attributeList));
                result.put("titleImg", img1(imgParams));
            }
        }

        if (Objects.equals("1", detailsImg)) {
            List<String> imgStrList = new ArrayList<>();
//            //生成图片列表
            if (StringUtils.isNotEmpty(pifiids)) {
                String[] split = pifiids.split(",");
                Attribute attribute = new Attribute();
                attribute.setIds(Arrays.asList(split));
                List<Attribute> attributeList = attributeMapper.selectAttributeList(attribute);
                attributeList =
                        attributeList.stream().filter(im -> StringUtils.isNotEmpty(im.getImgUrl())).collect(Collectors.toList());
//                if (attributeList.size() > 81) {
//                    attributeList = attributeList.subList(0, 81);
//                }
                int pointsDataLimit = 21;//限制条数
                Integer size = attributeList.size();
                List<JSONObject> jsList = new ArrayList<>();
                if (attributeList.size() > pointsDataLimit) {
                    try {
                        int part = size / pointsDataLimit;//分批数
                        List<BufferedImage> imgs = new ArrayList<>();
                        for (int i = 0; i < part; i++) {
                            List<Attribute> attributeListObj = attributeList.subList(0, pointsDataLimit);
                            log.info(String.valueOf(attributeListObj.size()));
                            BufferedImage bufferedImage = ImageUtils.merImg(attributeListObj);
                            byte[] bytes = ImgUntil.bufferedImageToByteArray(bufferedImage);
                            String path = uploadService.upload2Qiniu(bytes, gengerImg + UUIDGenerator.generate());
                            log.info("path={}", path);
                            imgStrList.add(path);
                            attributeList.subList(0, pointsDataLimit).clear();
                        }
                        imgs.clear();
                        if (!listJson.isEmpty()) {
                            BufferedImage bufferedImage = ImageUtils.merImg(attributeList);
                            byte[] bytes = ImgUntil.bufferedImageToByteArray(bufferedImage);
                            String path = uploadService.upload2Qiniu(bytes, gengerImg + UUIDGenerator.generate());
                            imgStrList.add(path);
                        }
                    } catch (Exception e) {
                        throw new GlobalException(e.getMessage());
                    }
                } else {
                    try {
                        BufferedImage bufferedImage = ImageUtils.merImg(attributeList);
                        byte[] bytes = ImgUntil.bufferedImageToByteArray(bufferedImage);
                        String path = uploadService.upload2Qiniu(bytes, gengerImg + UUIDGenerator.generate());
                        log.info("path={}", path);
                        imgStrList.add(path);
                    } catch (IOException e) {
                        throw new GlobalException(e.getMessage());
                    }
                }


                result.put("imgStrList", imgStrList);
            }
        }

//        if (Objects.equals("1", detailsImg)) {
//            //生成图片列表
//            String listJsonStr = MapUtils.getString(stringObjectMap, "listJson");
//            listJson.addAll(JSONObject.parseArray(listJsonStr, JSONObject.class));
//
//            LinkedHashSet<JSONObject> set = new LinkedHashSet<JSONObject>(listJson.size());
//            set.addAll(listJson);
//            listJson.clear();
//            listJson.addAll(set);
//            if (listJson.size() > 81) {
//                listJson = listJson.subList(0, 81);
//            }
//            List<String> imgStrList = new ArrayList<>();
//            int pointsDataLimit = 21;//限制条数
//            Integer size = listJson.size();
//            if (listJson.size() > pointsDataLimit) {
//                try {
//                    int part = size / pointsDataLimit;//分批数
//                    List<BufferedImage> imgs = new ArrayList<>();
//                    for (int i = 0; i < part; i++) {
//                        List<JSONObject> objectsList = listJson.subList(0, pointsDataLimit);
//                        log.info(String.valueOf(objectsList.size()));
//                        BufferedImage bufferedImage = ImageUtils.merImg(listJson);
//                        byte[] bytes = ImgUntil.bufferedImageToByteArray(bufferedImage);
//                        String path = uploadService.upload2Qiniu(bytes, gengerImg + UUIDGenerator.generate());
//                        log.info("path={}", path);
//                        imgStrList.add(path);
//                        listJson.subList(0, pointsDataLimit).clear();
//                    }
//                    imgs.clear();
//                    if (!listJson.isEmpty()) {
//                        BufferedImage bufferedImage = ImageUtils.merImg(listJson);
//                        byte[] bytes = ImgUntil.bufferedImageToByteArray(bufferedImage);
//                        String path = uploadService.upload2Qiniu(bytes, gengerImg + UUIDGenerator.generate());
//                        imgStrList.add(path);
//                    }
//                } catch (Exception e) {
//                    throw new GlobalException(e.getMessage());
//                }
//            } else {
//                try {
//                    BufferedImage bufferedImage = ImageUtils.merImg(listJson);
//                    byte[] bytes = ImgUntil.bufferedImageToByteArray(bufferedImage);
//                    String path = uploadService.upload2Qiniu(bytes, gengerImg + UUIDGenerator.generate());
//                    log.info("path={}", path);
//                    imgStrList.add(path);
//                } catch (IOException e) {
//                    throw new GlobalException(e.getMessage());
//                }
//            }
//            result.put("imgStrList", imgStrList);
//        }

        return result;
    }


    public String img1(Map<String, Object> params) {
        int initLeft = 200;

        try {
            // 获取网络图片
//            URL url = new URL("https://game.ikbh.top/logo/0230201105505.jpg");
            URL url = new URL("https://game.ikbh.top/logo/yjwjjj.jpg");
//            URL url = new URL("https://game.ikbh.top/logo/model4.jpg");
//            URL url = new URL("https://game.ikbh.top/logo/model5.jpg");
            BufferedImage image = ImageIO.read(url.openStream());
            // 创建画笔
            Graphics2D pen = image.createGraphics();
            // 设置画笔颜色为白色
            // pen.setColor(Color.WHITE);
            pen.setColor(new Color(255, 250, 255, 255));
            // 设置画笔字体样式为微软雅黑，斜体，文字大小为20px
            Font font = new Font("微软雅黑", Font.BOLD, 140);
            pen.setFont(font);
            FontMetrics fontMetrics = pen.getFontMetrics(font);

//            imgParams.put("title5", "贵族积分 ");
//            imgParams.put("title6", "五级铭文 ");
//            imgParams.put("title7", "王者印记 ");
//            imgParams.put("title8", "shiming ");

            // 写上水印文字和坐标
            pen.setColor(new Color(255, 255, 0, 255));
            String titleName = MapUtils.getString(params, "titleName");
            int textWidth = fontMetrics.stringWidth(titleName);
            pen.drawString(titleName, (image.getWidth() - textWidth) / 2, 300);
            pen.setColor(new Color(255, 255, 255, 255));
            //基本信息
            //英雄数量
            String cotent1 = MapUtils.getString(params, "cotent1");
            //皮肤数量
            String cotent2 = MapUtils.getString(params, "cotent2");
            //贵族等级
            String cotent3 = MapUtils.getString(params, "cotent3");
            //贵族积分
            String cotent4 = MapUtils.getString(params, "cotent4");
            String cotent5 = MapUtils.getString(params, "cotent5");
            String cotent6 = MapUtils.getString(params, "cotent6");
            String cotent7 = MapUtils.getString(params, "cotent7");
            String cotent8 = MapUtils.getString(params, "cotent8");
            String cotent9 = MapUtils.getString(params, "cotent9");
            String cotent10 = MapUtils.getString(params, "cotent10");

            String title1 = MapUtils.getString(params, "title1");
            String title2 = MapUtils.getString(params, "title2");
            String title3 = MapUtils.getString(params, "title3");
            String title4 = MapUtils.getString(params, "title4");
            String title5 = MapUtils.getString(params, "title5");
            String title6 = MapUtils.getString(params, "title6");
            String title7 = MapUtils.getString(params, "title7");
            String title9 = MapUtils.getString(params, "title9");
            String title10 = MapUtils.getString(params, "title10");


            font = new Font("微软雅黑", Font.BOLD, 100);
            pen.setFont(font);
//            String cotent = title1 + "：" + cotent1 + "       " + title2 + "：" + cotent2 + "      " + title3 + "：" +
//            cotent3 + "       " + title4 + "：" + cotent4;

            int title5With = fontMetrics.stringWidth(title1 + "  " + cotent1);
            pen.drawString(title1 + "  " + cotent1, initLeft, 500);

            int title6With = fontMetrics.stringWidth(title1 + "  " + cotent1 + initLeft);

            pen.drawString(title9 + " " + cotent9, 200, 2300);

            pen.drawString(title10 + "  " + cotent10, 2250, 2300);
            pen.drawString("  " + cotent8, 2300, 950);

            pen.drawString("  " + cotent8, 2300, 950);
            pen.drawString(title7 + "  " + cotent7, 100, 950);

            pen.drawString(title2, initLeft, 700);
            pen.setColor(new Color(255, 255, 255, 255));
            fontMetrics = pen.getFontMetrics(font);
            int title2With = fontMetrics.stringWidth(title2);

            pen.setColor(new Color(255, 0, 30, 255));
            pen.drawString(cotent2, title2With + initLeft + 50, 700);

            pen.setColor(new Color(255, 255, 255, 255));
            pen.drawString(title3, title2With + initLeft + 600, 700);

            pen.setColor(new Color(255, 0, 30, 255));
            fontMetrics = pen.getFontMetrics(font);
            int title3With = fontMetrics.stringWidth(title3);
            pen.drawString(cotent3, title2With + initLeft + 600 + title3With + 50, 700);

            pen.drawString(title6 + "  " + cotent6, title2With + initLeft + 600, 500);

            pen.setColor(new Color(255, 255, 255, 255));
            fontMetrics = pen.getFontMetrics(font);
            int cotent3With = fontMetrics.stringWidth(cotent3);
            pen.drawString(title4, title2With + initLeft + 800 + title3With + 150, 700);

            pen.setColor(new Color(255, 0, 30, 255));
            fontMetrics = pen.getFontMetrics(font);
            int title4With = fontMetrics.stringWidth(title4);
            pen.drawString(cotent4, title2With + initLeft + 800 + title3With + 160 + cotent3With + title4With + 50,
                    700);

            pen.drawString(title5 + "  " + cotent5, title2With + initLeft + 800 + title3With + 160 + 50, 500);

            font = new Font("微软雅黑", Font.BOLD, 90);
            pen.setFont(font);
            String des1Title = MapUtils.getString(params, "des1Title");
            String strContent1 = MapUtils.getString(params, "strContent1");
            if (StringUtils.isEmpty(strContent1)) {
                strContent1 = "--";
            }
            pen.setColor(new Color(255, 255, 255, 255));
//            pen.drawString(des1Title, initLeft, 1250);

            font = new Font("微软雅黑", Font.BOLD, 90);
            pen.setColor(new Color(255, 255, 0, 255));
            fontMetrics = pen.getFontMetrics(font);
            int des1TitleWith = fontMetrics.stringWidth(des1Title);
            int height = drawStringWithFontStyleLineFeedTitle(pen, strContent1, image.getWidth() - 300,
                    des1TitleWith + initLeft, 1240, font, initLeft, null);
            //内容

            String remake = MapUtils.getString(params, "remake");
            pen.setColor(new Color(255, 250, 0, 255));
            int remakeWidth = fontMetrics.stringWidth(remake + ": ");
            pen.drawString(remake, (image.getWidth() - remakeWidth) / 2, 2500);
            pen.drawString(des1Title, (image.getWidth() - des1TitleWith) / 2, 2650);


            byte[] bytes = ImgUntil.bufferedImageToByteArray(image);
            String path = uploadService.upload2Qiniu(bytes, gengerImg + UUIDGenerator.generate());
            log.info("path={}", path);
            return path;
        } catch (Exception e) {
            throw new GlobalException("请输入完整信息");
        }
    }


    /**
     * 根据指定宽度自动换行
     *
     * @param g
     * @param maxWdith
     * @param strContent
     * @param loc_X
     * @param loc_Y
     * @param font
     */
    public static int drawStringWithFontStyleLineFeedTitle(Graphics g, String strContent, int maxWdith, int loc_X,
                                                           int loc_Y, Font font, Integer initLeft, Integer lineHeight) {
        if (Objects.isNull(lineHeight)) {
            lineHeight = 20;
        }
        g.setFont(font);

        List<Attribute> attributeList = JSONObject.parseArray(strContent, Attribute.class);

        if (attributeList.size() > 33) {
            attributeList = attributeList.subList(0, 33);
        }
        int i = 0;
        int line = 1;
        for (Attribute attribute : attributeList) {

            if (!Objects.isNull(attribute)) {
                Long sort = attribute.getSort();
//                pen.setColor(new Color(255, 255, 0, 255));
                if (Objects.equals(-1l, sort)) {
                    g.setColor(new Color(0, 255, 217, 255));
                }
                if (Objects.equals(0l, sort)) {
                    g.setColor(new Color(230, 255, 0, 255));
                }
                if (line == 1) {
                    g.drawString(attribute.getFieldName(), i * 700 + 200, 960 + line * 145);
                } else {
                    g.drawString(attribute.getFieldName(), (i - 1) * 700 + 200, 960 + line * 145);
                }

                if (i % 4 == 0 && i != 0) {
                    line++;
                    i = 0;
                }
                i++;
            }

        }
        return 0;

    }

    @Override
    public List<Map<String, Object>> allSkinType() {

        Map<String, Object> params = new TreeMap<>();
        params.put("pg", "apiWzAllQuFu");
        params.put("gameId", "10");
        log.info("角色列表请求参数={}", JSONObject.toJSONString(params));
        String url = "http://mh.poxiaowy.com/yingdi/yingdipifuController.php?pg=apiFindByIDGoodsClass&gameId=10";
        String response = HttpUtils.doPostForm(url, params, null);
        log.info("分类列表返回参数={}", response);
        JSONObject jsonObject = JSONObject.parseObject(response);
        String msg = jsonObject.getString("msg");
        msg = MapUntils.unicodeToString(msg);
        log.info("分类列表返回参数={}", msg);
        List<Map<String, Object>> resultMap = new ArrayList<>();
        if ("0".equals(jsonObject.getString("code"))) {
            String data = jsonObject.getString("data");
            JSONArray dataList = JSONObject.parseArray(data);
            for (Object o : dataList) {
                Map<String, Object> resu = new HashMap<>();
                String s = JSONObject.toJSONString(o);
                JSONObject jsonObject1 = JSONObject.parseObject(s);
                resu.put("id", jsonObject1.getString("id"));
                resu.put("brandname", jsonObject1.getString("brandname"));
                resu.put("pbrandname", jsonObject1.getString("pbrandname"));
                resultMap.add(resu);
            }
        }
        return resultMap;
    }

    @Override
    public List<Map<String, Object>> allSkinTypeTwo(Long brandId) {

        Map<String, Object> params = new TreeMap<>();
        params.put("pg", "apiFindByIDGoodsSki");
        params.put("gameId", brandId);
        log.info("二级分类列表请求参数={}", JSONObject.toJSONString(params));
        String url =
                "http://mh.poxiaowy.com/yingdi/yingdipifuController.php?pg=apiFindByIDGoodsSkin&brandId=" + brandId;
        String response = HttpUtils.doPostForm(url, params, null);
        log.info("二级分类列表返回参数={}", response);
        JSONObject jsonObject = JSONObject.parseObject(response);
        String msg = jsonObject.getString("msg");
        msg = MapUntils.unicodeToString(msg);
        log.info("二级分类列表返回参数={}", msg);
        List<Map<String, Object>> resultMap = new ArrayList<>();
        if ("0".equals(jsonObject.getString("code"))) {
            String data = jsonObject.getString("data");
            JSONArray dataList = JSONObject.parseArray(data);
            for (Object o : dataList) {
                Map<String, Object> resu = new HashMap<>();
                String s = JSONObject.toJSONString(o);
                JSONObject jsonObject1 = JSONObject.parseObject(s);
                resu.put("id", jsonObject1.getString("id"));
                resu.put("brandname", jsonObject1.getString("brandname"));
                resu.put("pbrandname", jsonObject1.getString("pbrandname"));
                resultMap.add(resu);
            }
        }
        return resultMap;
    }

    @Override
    public List<Map<String, Object>> allSkin() {
        Map<String, Object> params = new TreeMap<>();
        params.put("pg", "apiFindByAscriptionSortAll");
        params.put("gameId", 10);
        log.info("皮肤列表请求参数={}", JSONObject.toJSONString(params));
        String url = "http://mh.poxiaowy.com/yingdi/yingdipifuController.php?pg=apiFindByAscriptionSortAll&gameId=10";
        String response = HttpUtils.doPostForm(url, params, null);
        log.info("皮肤分类列表返回参数={}", response);
        JSONObject jsonObject = JSONObject.parseObject(response);
        String msg = jsonObject.getString("msg");
        msg = MapUntils.unicodeToString(msg);
        log.info("二级分类列表返回参数={}", msg);
        List<Map<String, Object>> resultMap = new ArrayList<>();
        if ("0".equals(jsonObject.getString("code"))) {
            String data = jsonObject.getString("data");
            JSONArray dataList = JSONObject.parseArray(data);
            for (Object o : dataList) {
                Map<String, Object> resu = new HashMap<>();
                String s = JSONObject.toJSONString(o);
                JSONObject jsonObject1 = JSONObject.parseObject(s);
                resu.put("id", jsonObject1.getString("id"));
                resu.put("title", jsonObject1.getString("title"));
                resu.put("children", jsonObject1.getString("children"));
                resultMap.add(resu);
            }
        }
        return resultMap;
    }


    /**
     * 王者荣耀自动获取
     *
     * @param params
     * @return
     */
    @Override
    public Map<String, Object> gengerV2(Map<String, Object> params) {


        Map<String, Object> result = new HashMap<>();
        //1、重要信息
        //2、皮肤


        String userInfoUrl = "https://ssl.kohsocialapp.qq.com:10001/game/battleprofile";
        //营地Id
        String campId = MapUtils.getString(params, "campId");

        Map<String, Object> userInfoParams = new HashMap<>();

        userInfoParams.put("cChannelId", 0);
        userInfoParams.put("cClientVersionCode", "67230122033123");
        userInfoParams.put("cClientVersionName", "6.72.301");
        userInfoParams.put("cCurrentGameId", "20001");
        userInfoParams.put("cGameId", "20001");
        userInfoParams.put("cGzip", "1");
        userInfoParams.put("cRand", "1650682029405");
        userInfoParams.put("cSystem", "ios");
        userInfoParams.put("cSystemVersionCode", "15.0");
        userInfoParams.put("cSystemVersionName", "iOS");
        userInfoParams.put("friendUserId", "324015131");
        userInfoParams.put("gameAreaId", "2");
        userInfoParams.put("gameId", "20001");
        userInfoParams.put("gameOpenId", "572D7600606F2F88832E2EEDB6824EE9");
        userInfoParams.put("gameRoleId", "2013141209");
        userInfoParams.put("gameServerId", "2078");
        userInfoParams.put("gameUserSex", "1");
        userInfoParams.put("isTestFlight", "0");
        userInfoParams.put("key1", "1c1157bd-d155-42b5-a7d4-a713ab00b96d");
        userInfoParams.put("key10", "3867443200");
        userInfoParams.put("key11", "ARM64");
        userInfoParams.put("key13", "WiFi");
        userInfoParams.put("key14", "%E4%B8%AD%E5%9B%BD%E7%A7%BB%E5%8A%A8");
        userInfoParams.put("key15", "00000000-0000-0000-0000-000000000000");
        userInfoParams.put("key18", "iPhone14%2C5");
        userInfoParams.put("key19", "0.000000");
        userInfoParams.put("key20", "0.000000");
        userInfoParams.put("key21", "");
        userInfoParams.put("key22", "");
        userInfoParams.put("key6", "390");
        userInfoParams.put("key7", "844");
        userInfoParams.put("key9", "iPhone");
        userInfoParams.put("noMatch", "0");
        userInfoParams.put("openId", "33E8882491303DBB19EC1F9B27421901");
        userInfoParams.put("recommendPrivacy", "0");
        userInfoParams.put("reportHashValue", "10784803456");
        userInfoParams.put("roleId", "");
        userInfoParams.put("rsVersion", "3");
        userInfoParams.put("token", "bFRMfnbk");
        userInfoParams.put("userId", "416923392");

        String response = HttpUtils.doPostForm(userInfoUrl, userInfoParams, null);
        System.out.println(response);
        JSONObject userInfo = JSONObject.parseObject(response);

//        gameAreaId、gameServerId、gameRoleId、friendUserId
        JSONObject data = userInfo.getJSONObject("data");
        JSONObject rolecard = data.getJSONObject("rolecard");
        String areaId = rolecard.getString("areaId");
        String serverId = rolecard.getString("serverId");
        String roleId = rolecard.getString("roleId");

        String skinListUrl = "https://ssl.kohsocialapp.qq.com:10001/play/h5getheroskinlist";
        String skinResult = HttpUtils.doPostForm(skinListUrl, userInfoParams, null);
        JSONObject skinInfo = JSONObject.parseObject(skinResult);
        System.out.println(skinInfo);
        return null;
    }

    private List<JSONObject> testRoleList(String yindi) {
//
//        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("yingdiToken");
//        String token = sysDictDataList.get(0).getDictValue();
//        String userid = sysDictDataList.get(0).getDictLabel();
//
//        Map<String, Object> params = new HashMap<>();
////        params.put("openId", "oFhrws8OqdftI_7819rEA4eYgMsU");
////        params.put("targetUserId", yindi);
//        params.put("gameId", "20001");
//        params.put("friendUserId", yindi);
//        params.put("token", token);
//        params.put("userId", userid);
//
//
////        Map<String, String> head = new HashMap<>();
////        head.put("token", token);
////        head.put("userId", "493258559");
////        head.put("userId", "userid");
////        head.put("content-type", "application/json");
////        head.put("Content-Length", "790");
////        head.put("connection", "keep-alive");
//
//
////        String url = "https://kohcamp.qq.com/game/profile/index";
//        String url = "https://ssl.kohsocialapp.qq.com:10001/game/battleprofile";
//        try {
//            log.info("请求参数={}", JSON.toJSONString(params));
//            String s = HttpUtils.doPostForm(url, params, null);
//            log.info("返回参数={}", s);
//            JSONObject jsonObject = JSON.parseObject(s);
//            if ("0".equals(jsonObject.getString("result"))) {
//                List<Map<String, Object>> result = new ArrayList<>();
//                JSONObject data = jsonObject.getJSONObject("data");
//                String roleList = data.getString("rolelist");
//                if (StringUtils.isNotEmpty(roleList)) {
//                    JSONArray objects = JSON.parseArray(roleList);
//                    for (Object object : objects) {
//                        Map<String, Object> map = new HashMap<>();
//
//                        String string = JSON.toJSONString(object);
//                        JSONObject mapJson = JSONObject.parseObject(string);
//                        String areaId = mapJson.getString("areaId");
//                        if ("1".equals(areaId)) {
//                            areaId = "安卓Q";
//                        } else if ("2".equals(areaId)) {
//                            areaId = "苹果Q";
//                        } else if ("3".equals(areaId)) {
//                            areaId = "安卓WX";
//                        } else if ("4".equals(areaId)) {
//                            areaId = "苹果WX";
//                        }
//
//                        map.put("areaName", areaId);
//                        map.put("grade", mapJson.getLong("level"));
//                        map.put("roleId", mapJson.getString("roleId"));
//                        map.put("roleJob", mapJson.getString("roleJob"));
//                        map.put("roleName", mapJson.getString("roleName"));
//                        map.put("serverName", mapJson.getString("serverName"));
//                        result.add(map);
//                    }
//                }
//
//                Collections.sort(result,
//                        (o1, o2) -> Integer.parseInt(o2.get("grade").toString()) - Integer.parseInt(o1.get("grade").toString()));
//
//                return result;
//            } else {
//                SysDictData sysDictData = sysDictDataList.get(0);
//                SysDictData noMax = sysDictDataList.stream().max(Comparator.comparing(SysDictData::getDictSort)).get();
//                Long newsort = noMax.getDictSort() + 1l;
//                sysDictData.setDictSort(newsort);
//                sysDictDataMapper.updateDictData(sysDictData);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
        String url = "";
        String path = "qrCode/wzry/wzryRole";

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
            }
        }

        Map<String, Object> params = new HashMap<>();
        params.put("campId", yindi);

        String res = HttpUtil.get(url + path, params);
        System.out.println(res);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {
            return JSONObject.parseArray(jsonObject.getString("data"), JSONObject.class);
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }
    }


    private Map<String, Object> testRoleInfo(String yindi, String roleId) {

        Map<String, Object> resultMap = new HashMap<>();

        String url = "https://ssl.kohsocialapp.qq.com:10001/play/h5getheroskinlist";

        Map<String, Object> head = new HashMap<>();

        head.put("content-type", "application/x-www-form-urlencoded");

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("yingdiToken");
        String token = sysDictDataList.get(0).getDictValue();

        Map<String, Object> params = new HashMap<>();
        params.put("openId", "oFhrws8OqdftI_7819rEA4eYgMsU");
        params.put("userId", "493258559");
//        params.put("token", "Zkw9b6eE");
        params.put("token", token);
        params.put("cClientVersionName", "6.73.106");
        params.put("cSystemVersionCode", "23");
        params.put("uniqueRoleId", roleId);

        String s = HttpUtils.doPostForm(url, params, head);

        //内测
        List<String> neiceids = new ArrayList<>();
        List<String> neiceName = new ArrayList<>();
        //典藏
        List<String> diancangids = new ArrayList<>();
        List<String> diancangName = new ArrayList<>();
        //限定
        List<String> xiandingids = new ArrayList<>();
        List<String> xiandingName = new ArrayList<>();
        //星原
        List<String> xingyuanids = new ArrayList<>();
        List<String> xingyuanName = new ArrayList<>();
        //传说
        List<String> chuanshuoids = new ArrayList<>();
        List<String> chuanshuoName = new ArrayList<>();
        //史诗
        List<String> shishiids = new ArrayList<>();
        List<String> shishiName = new ArrayList<>();

        //获取皮肤类型列表
        JSONObject jsonObject = JSON.parseObject(s);
        if ("0".equals(jsonObject.getString("result"))) {
            JSONObject data = jsonObject.getJSONObject("data");
            JSONObject skinCountInfo = data.getJSONObject("skinCountInfo");
            String skinTypeList = skinCountInfo.getString("skinTypeList");
            JSONArray objects = JSON.parseArray(skinTypeList);


            Integer skinIds[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
                    24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
                    34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45};


            //首先拿到需要拼图的皮肤类型
            //查找对应的皮肤id
            //筛选已有的皮肤
            //返回信息

            //总皮肤列表
            String heroSkinConfList = data.getString("heroSkinConfList");

            List<String> classIds = new ArrayList<>();
            JSONObject heroSkinConfJson = JSON.parseObject(heroSkinConfList);
            for (String s1 : heroSkinConfJson.keySet()) {
                String string = heroSkinConfJson.getString(s1);
                JSONObject parseObject = JSON.parseObject(string);
                String classType = parseObject.getString("classType");
                JSONArray classObjArr = JSON.parseArray(classType);
                if (CollectionUtils.isNotEmpty(classObjArr)) {
                    for (Object o : classObjArr) {
                        if (Arrays.asList(skinIds).contains(Integer.valueOf(o.toString()))) {
                            classIds.add(s1);
                        }
                    }
                }
            }
            //皮肤列表
            String heroSkinList = data.getString("heroSkinList");
            JSONArray heroSkinListJson = JSON.parseArray(heroSkinList);

            List<JSONObject> resultJsonObj = new ArrayList<>();

            for (Object o : heroSkinListJson) {
                JSONObject skinObj = JSON.parseObject(JSON.toJSONString(o));
                String skinId = skinObj.getString("skinId");
                for (String classid : classIds) {
                    if (skinId.equals(classid)) {
                        resultJsonObj.add(skinObj);
                    }
                }
            }


            //https://ssl.kohsocialapp.qq.com:10001/game/battleprofile


            String roleUrl = "https://ssl.kohsocialapp.qq.com:10001/game/battleprofile";
            Map<String, Object> paramsRoleList = new HashMap<>();
            paramsRoleList.put("friendUserId", yindi);
            paramsRoleList.put("roleId", roleId);
            paramsRoleList.put("gameId", "20001");
            paramsRoleList.put("token", token);
            paramsRoleList.put("userId", "493258559");
            paramsRoleList.put("cClientVersionName", "6.72.301");

            String roleList = HttpUtils.doPostForm(roleUrl, paramsRoleList, head);

            JSONObject roleJson = JSON.parseObject(roleList);
            String result = roleJson.getString("result");
            if ("0".equals(result)) {
                String roleData = roleJson.getString("data");
                JSONObject roleDataJson = JSON.parseObject(roleData);
                String rolecard = roleDataJson.getString("rolecard");
                JSONObject rolecardJson = JSON.parseObject(rolecard);

                String links = rolecardJson.getString("links");
                String areaId = rolecardJson.getString("areaId");
                if ("1".equals(areaId)) {
                    areaId = "安卓Q";
                } else if ("2".equals(areaId)) {
                    areaId = "苹果Q";
                } else if ("3".equals(areaId)) {
                    areaId = "安卓WX";
                } else if ("4".equals(areaId)) {
                    areaId = "苹果WX";
                }
                resultMap.put("areaName", areaId);


                JSONArray linksArr = JSON.parseArray(links);
                for (int i = 0; i < linksArr.size(); i++) {
                    if (i == 0) {
                        Object o = linksArr.get(i); // 英雄
                        String string = JSON.toJSONString(o);
                        JSONObject jsonObject1 = JSON.parseObject(string);
                        String name = jsonObject1.getString("name");
                        JSONArray objects1 = JSON.parseArray(name);
                        Object o1 = objects1.get(1);
                        log.info("英雄数量={}", o1);
                        resultMap.put("heros", o1);
                    }
                    if (i == 1) {
                        Object o = linksArr.get(i); // 皮肤
                        String string = JSON.toJSONString(o);
                        JSONObject jsonObject1 = JSON.parseObject(string);
                        String name = jsonObject1.getString("name");
                        JSONArray objects1 = JSON.parseArray(name);
                        Object o1 = objects1.get(1);
                        log.info("皮肤数量={}", o1);
                        resultMap.put("skins", o1);
                    }
                }
                //英雄数量
                //皮肤数量
                //贵族登记
                String nobilityLevel = rolecardJson.getString("nobilityLevel");
                log.info("贵族等级={}", nobilityLevel);
                resultMap.put("nobilityLevel", nobilityLevel);

            } else {
                SysDictData sysDictData = sysDictDataList.get(0);
                SysDictData noMax = sysDictDataList.stream().max(Comparator.comparing(SysDictData::getDictSort)).get();
                Long newsort = noMax.getDictSort() + 1l;
                sysDictData.setDictSort(newsort);
                sysDictDataMapper.updateDictData(sysDictData);
            }
            log.info(JSON.toJSONString(resultJsonObj));

            Set<JSONObject> imgSet = new HashSet();
            imgSet.addAll(resultJsonObj);

            resultMap.put("skinList", imgSet);
            List<String> szTitle = imgSet.stream().map(i -> i.getString("szTitle")).collect(Collectors.toList());
            String join = StringUtils.join(szTitle, " ");

            String des = "大区：" + MapUtils.getString(resultMap, "areaName") + " 英雄数量：" + MapUtils.getString(resultMap,
                    "heros") + " 皮肤数量：" + MapUtils.getString(resultMap, "skins") +
                    " 贵族等级：" + MapUtils.getString(resultMap, "nobilityLevel") + " " + join;

            resultMap.put("des", des);

//            JSONObject imgJson = new JSONObject();
//            List<String> szSmallIcon = resultJsonObj.stream().map(js -> js.getString("szSmallIcon")).collect
//            (Collectors.toList());
//            log.info(JSONObject.toJSONString(szSmallIcon));
//            Set<String> imgSet = new HashSet();
//            imgSet.addAll(szSmallIcon);
//            imgJson.put("imgList",imgSet);
//            log.info(String.valueOf(imgSet.size()));
//            Map<String, Object> stringObjectMap = attributeService.mergeImage(imgJson);
//            resultMap.put("img",stringObjectMap);

        }

        return resultMap;

    }

    public static void main(String[] args) {

//        Map<String, Object> reqParams = new TreeMap<>();
//        reqParams.put("pg", "shouquanYingDi");
//        reqParams.put("authType", "2");
//        reqParams.put("yingdi", "755716196");
//
//        log.info("和平经营授权请求参数={}", JSONObject.toJSONString(reqParams));
//        String url = "http://mh.poxiaowy.com/generator/chiji/chijiApiController.php";
//        String response = HttpUtils.doPostForm(url, reqParams, null);
//        log.info("和平经营授权返回参数={}", response);


//        Map<String, Object> reqParams = new TreeMap<>();
////        reqParams.put("quality", "5");
//        reqParams.put("yingdi", "755716196");
//        reqParams.put("businessId", "11347");
//
//        String cover = MapUntils.getCover(reqParams);
//        cover = cover.replace("yingdi","yingdiId")+"key=x8logf11d6o898l83botgg105c9ky83rjoi";
////        System.out.println(cover+);
//        String sign = DigestUtils.md5Hex(cover).toUpperCase();
//        reqParams.put("sign",sign);
//        System.out.println(sign);
//        reqParams.put("pg", "apiCjAutoTitle");
//
//        String url = "http://mh.poxiaowy.com/generator/chiji/chijiApiController.php";
//        String response = HttpUtils.doPostForm(url, reqParams, null);
//        System.out.println(response);
//
//        JSONObject parse = JSONObject.parseObject(response);
//        String code = parse.getString("code");
//        if (Objects.equals("0",code)){
//
//
//
//        }else {
//            throw new GlobalException("");
//        }


//        String url = "https://mh.poxiaowy.com/admin/adminController.php";
//        Map<String, Object> reqParams = new TreeMap<>();
//        reqParams.put("pg", "findByAscriptionSortSkinAllOrderSort");
//        reqParams.put("brandId", "11");
//
//        String response = HttpUtils.doPostForm(url, reqParams, null);
//        JSONObject jsonObject = JSONObject.parseObject(response);
//        if (Objects.equals("20000", jsonObject.getString("code"))) {
//
//            String data = jsonObject.getString("data");
//            List<JSONObject> jsonObjects = JSONObject.parseArray(data, JSONObject.class);
//            for (JSONObject object : jsonObjects) {
//
//
//            }
//
//        }

//        String url = "http://mh.poxiaowy.com/api/api.php?pg=getGameId";
//        Map<String, Object> reqParams = new TreeMap<>();
//        reqParams.put("gameId", "11");
//
//        String response = HttpUtils.doPostForm(url, reqParams, null);
//        System.out.println(response);

        String str = "人生自古谁无死，留取丹心照汗青";
        Integer start = startChar(str, "，");
        System.out.println(str.substring(start + 1, str.length()));

    }

    @Override
    public Map<String, Object> getQRcode(Map<String, Object> params) {
//
//        String yingdi = MapUtils.getString(params, "yingdi");
//        String authType = MapUtils.getString(params, "authType");
//
//        Map<String, Object> reqParams = new TreeMap<>();
//        reqParams.put("pg", "shouquanYingDi");
//        reqParams.put("authType", authType);
//        reqParams.put("yingdi", yingdi);
//
//        log.info("和平经营授权请求参数={}", JSONObject.toJSONString(reqParams));
//        String url = "http://mh.poxiaowy.com/generator/chiji/chijiApiController.php";
//        String response = HttpUtils.doPostForm(url, reqParams, null);
//        log.info("和平经营授权返回参数={}", response);
//        JSONObject jsonObject = JSONObject.parseObject(response);
//
//        Map<String, Object> result = new HashMap<>();
//
//        if (Objects.equals("1", jsonObject.getString("code"))) {
//            result.put("url", jsonObject.getString("url"));
//        } else {
//            new GlobalException(jsonObject.getString("msg"));
//        }
//        return result;
        String url = "";
        String path = "hpjyv2/getqrcode";
        String username = "";
        String pwd = "";
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
//                url = "http://192.168.3.105:9999/";
            }
            if ("username".equals(dictData.getDictLabel())) {
                username = dictData.getDictValue();
            } else if ("pwd".equals(dictData.getDictLabel())) {
                pwd = dictData.getDictValue();
            }
        }
        Map<String, Object> tokenPrams = new HashMap<>();
        tokenPrams.put("username", username);
        tokenPrams.put("pwd", pwd);

        String res = HttpUtil.get(url + path, params);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {
            return JSONObject.parseObject(jsonObject.getString("data"));
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }
    }

    /**
     * 字段说明
     * fushibi  服饰币
     * jinbi  金币
     * dianquan 点券
     * nowHeat 当前热力
     *
     * @param params
     * @return
     */

    @Override
    public Map<String, Object> getHPDatacode(Map<String, Object> params) {
        try {
            String url = "";
            String qrsig = params.get("qrsig").toString();
            String authType = params.get("authType").toString();
            String path = "hpjyv2/getHPDatacodeParam";
            String username = "";
            String pwd = "";
            List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
            for (SysDictData dictData : sysDictDataList) {
                if ("url".equals(dictData.getDictLabel())) {
                    url = dictData.getDictValue();
//                    url = "http://192.168.3.105:9999/";
                }
                if ("username".equals(dictData.getDictLabel())) {
                    username = dictData.getDictValue();
                } else if ("pwd".equals(dictData.getDictLabel())) {
                    pwd = dictData.getDictValue();
                }
            }
            Map<String, Object> tokenPrams = new HashMap<>();
            tokenPrams.put("username", username);
            tokenPrams.put("pwd", pwd);
            tokenPrams.put("qrsig", qrsig);
            tokenPrams.put("authType", authType);
            String res = HttpUtil.get(url + path, tokenPrams);
            JSONObject jsonObject = JSONObject.parseObject(res);
            String code = jsonObject.getString("code");
            if (Objects.equals("200", code)) {
                return JSONObject.parseObject(jsonObject.getString("data"));
            } else {
                throw new GlobalException(jsonObject.getString("msg"));
            }
        } catch (Exception e) {
            throw new GlobalException(e.getMessage());
        }
    }


    public static Map<String, Object> getAuth() {

//        String campId = MapUtils.getString(params, "campId");
//        String authType = MapUtils.getString(params, "authType");

//        Map<String, Object> reqParams = new TreeMap<>();
//        reqParams.put("pg", "shouquanYingDi");
//        reqParams.put("authType", "1");
//        reqParams.put("yingdi", "541737693");
//
//        log.info("和平经营授权请求参数={}", JSONObject.toJSONString(reqParams));
//        String url = "http://mh.poxiaowy.com/generator/chiji/chijiApiController.php";
//        String response = HttpUtils.doPostForm(url, reqParams, null);
//        log.info("和平经营授权返回参数={}", response);
        return null;
    }


    public static Integer startChar(String str, String specialChar) {
        Matcher matcher = Pattern.compile(specialChar).matcher(str);
        if (matcher.find()) {
            System.out.println(matcher.start());
            Integer start = matcher.start();
            return start;
        }
        return null;
    }

    /**
     * 远程读取image转换为Base64字符串
     *
     * @param imgUrl
     * @return
     */
    private String ImageBase64(String imgUrl) {
        URL url = null;
        InputStream is = null;
        ByteArrayOutputStream outStream = null;
        HttpURLConnection httpUrl = null;
        try {
            url = new URL(imgUrl);
            httpUrl = (HttpURLConnection) url.openConnection();
            httpUrl.connect();
            httpUrl.getInputStream();
            is = httpUrl.getInputStream();

            outStream = new ByteArrayOutputStream();
            //创建一个Buffer字符串
            byte[] buffer = new byte[1024];
            //每次读取的字符串长度，如果为-1，代表全部读取完毕
            int len = 0;
            //使用一个输入流从buffer里把数据读取出来
            while ((len = is.read(buffer)) != -1) {
                //用输出流往buffer里写入数据，中间参数代表从哪个位置开始读，len代表读取的长度
                outStream.write(buffer, 0, len);
            }
            // 对字节数组Base64编码
            return new BASE64Encoder().encode(outStream.toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outStream != null) {
                try {
                    outStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (httpUrl != null) {
                httpUrl.disconnect();
            }
        }
        return imgUrl;
    }

    //    public static List<Map<String, Object>> sortMap(Map<String, Object> data, List<Map<String, Object>> yList,
//    String type) {
//        if (Objects.equals(data.get("sort"), "asc")) {
//            yList.sort(Comparator.comparingInt(o -> Integer.parseInt(o.get(type).toString())));
//            return yList;
//        } else {
//            Collections.sort(yList, (o1, o2) -> Integer.parseInt(o2.get(type).toString()) - Integer.parseInt(o1.get
//            (type).toString()));
//        }
//        return yList;
//    }
    @Override
    public JSONObject tdCode() {

        String url = "";
        String path = "qrCode/tdCode";

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
            }
        }

        String res = HttpUtil.get(url + path);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {
            return JSONObject.parseObject(jsonObject.getString("data"));
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }
    }

    @Override
    public JSONObject tdCfCode(String gameId, String type) {

        String url = "";
        String path = "qrCode/cf/getXLLogin";

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
            }
        }

        String res = HttpUtil.get(url + path + "?gameId=" + gameId + "&type=" + type);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {
            return JSONObject.parseObject(jsonObject.getString("data"));
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }
    }

    @Override
    public JSONObject getXLLoginFindRe(String uuid, String gameId, String type) {
        String url = "";
        String path = "qrCode/cf/getXLLoginFindRe";

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
            }
        }

        String res = HttpUtil.get(url + path + "?uuid=" + uuid + "&gameId=" + gameId + "&type=" + type);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {
            return JSONObject.parseObject(jsonObject.getString("data"));
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }
    }

    @Override
    public JSONObject getXLGameInfo(String tencentId, String gameId) {
        String url = "";
        String username = "";
        String pwd = "";
        String path = "qrCode/cf/getXLGameInfo";

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
            }
            if ("username".equals(dictData.getDictLabel())) {
                username = dictData.getDictValue();
            }
            if ("pwd".equals(dictData.getDictLabel())) {
                pwd = dictData.getDictValue();
            }
        }

        String res = HttpUtil.get(url + path + "?tencentId=" + tencentId + "&gameId=" + gameId + "&username=" + username + "&pwd=" + pwd);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {
            return JSONObject.parseObject(jsonObject.getString("data"));
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }
    }

    @Override
    public String getToken(Map<String, Objects> params) {

        String uuid = MapUtils.getString(params, "uuid");
        String type = MapUtils.getString(params, "type");

        String url = "";
        String username = "";
        String pwd = "";
        String path = "qrCode/lol/getToken";

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
            }
            if ("username".equals(dictData.getDictLabel())) {
                username = dictData.getDictValue();
            } else if ("pwd".equals(dictData.getDictLabel())) {
                pwd = dictData.getDictValue();
            }
        }

        Map<String, Object> tokenPrams = new HashMap<>();
        tokenPrams.put("username", username);
        tokenPrams.put("pwd", pwd);
        tokenPrams.put("uuid", uuid);
        tokenPrams.put("type", type);

        String res = HttpUtil.get(url + path, tokenPrams);

        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {
            String data = jsonObject.getString("data");
            return data;
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }
    }

    @Override
    public JSONObject wwqyQrCode() {


        String url = "";
        String path = "qrCode/val/tdCode";

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
            }
        }

        String res = HttpUtil.get(url + path);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {
            return JSONObject.parseObject(jsonObject.getString("data"));
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }

    }

    @Override
    public JSONObject wwqyGetRole(Map<String, Object> params) {

        String uuid = MapUtils.getString(params, "uuid");
        String type = MapUtils.getString(params, "type");

        String url = "";
        String username = "";
        String pwd = "";
        String path = "qrCode/VALORANT/getToken";

        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("gameDataGet");
        for (SysDictData dictData : sysDictDataList) {
            if ("url".equals(dictData.getDictLabel())) {
                url = dictData.getDictValue();
            }
            if ("username".equals(dictData.getDictLabel())) {
                username = dictData.getDictValue();
            } else if ("pwd".equals(dictData.getDictLabel())) {
                pwd = dictData.getDictValue();
            }
        }

        Map<String, Object> tokenPrams = new HashMap<>();
        tokenPrams.put("username", username);
        tokenPrams.put("pwd", pwd);
        tokenPrams.put("uuid", uuid);
        tokenPrams.put("type", type);

        String res = HttpUtil.get(url + path, tokenPrams);
        System.out.println(res);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String code = jsonObject.getString("code");
        if (Objects.equals("200", code)) {

            return jsonObject.getJSONObject("data");
        } else {
            throw new GlobalException(jsonObject.getString("msg"));
        }
    }

    private SysDictData getDict(String dictType) {
        List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType);
        if (CollectionUtils.isNotEmpty(dictDatas)) {
            return dictDatas.get(0);
        }
        return null;
    }

    @Override
    public JSONObject jccQrCode() {

        String ptqrshow = "https://xui.ptlogin2.qq.com/ssl/ptqrshow?s=8&e=0&appid=716027609&type=0&t=0.9330058021941994&u1=http%3A%2F%2Fconnect.qq.com&daid=381&pt_3rd_aid=100543809";

        URL url = null;
        String response = null;
        BufferedReader in = null;
        JSONObject result = new JSONObject();
        try {

            SysDictData leishenProxies = getDict("leishenProxies");
            String addrResult = HttpUtil.get(leishenProxies.getRemark());

            Map<String, Object> params = new HashMap<>();
            params.put("accept", "*/*");
            params.put("connection", "Keep-Alive");
            params.put("Host", "xui.ptlogin2.qq.com");
//            conn.setRequestProperty("Cookie", "qrsig=b8282569247cc87d35ed27150fba6034e33de6d33451d9154506f8a01e4ad8ed6f524ca85944fe10d344bd4fa547d53810d304df8bd3f4fae755492ba27a650e");
            params.put("Referer", "https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=716027609&pt_3rd_aid=100543809&daid=381&pt_skey_valid=0&style=35&force_qr=1&autorefresh=1&s_url=http%3A%2F%2Fconnect.qq.com&refer_cgi=m_authorize&ucheck=1&fall_to_wv=1&status_os=16.0&redirect_uri=auth%3A%2F%2Fwww.qq.com&client_id=100543809&response_type=token&scope=get_user_info%2Cget_simple_userinfo&sdkp=i&sdkv=3.5.11_lite&state=test&status_machine=iPhone13%2C2&switch=1&traceid=DEF697D1-75A6-4BFF-9200-6A181EC7CF60_1686367859&_wv=16777218&qr_login=1&loginfrom=main&h5sig=X8AeRmP9IoJru6y2o3KIdXYkiPMX6sKiy559pQ9FeYU&loginty=7");

            HttpResponse response1 = ProxiesUtil.ProxiesPost(ptqrshow, addrResult, null, params.toString());

            byte[] by = new byte[1024];
            String line = null;
            ByteArrayOutputStream data = new ByteArrayOutputStream();
            in = new BufferedReader(new InputStreamReader(response1.bodyStream()));
            int len = -1;
            InputStream is = response1.bodyStream();
            while ((len = is.read(by)) != -1) {
                data.write(by, 0, len);
            }

            // 对字节数组Base64编码
            byte[] bytes = Base64.encodeBase64(data.toByteArray());
            String base64 = new String(bytes);
            response = "data:image/png" + ";base64," + base64;

            Map headers = response1.headers();
            Set<String> keys = headers.keySet();
            for (String key : keys) {
                String val = response1.header(key);
                if (Objects.equals("Set-Cookie", key)) {
                    String[] split = val.replace("qrsig=", "").split(";");
                    result.put("uuid", split[0]);
                    redisCache.setCacheObject(split[0], addrResult, 10, TimeUnit.MINUTES);
                }
                log.info(key + "    " + val);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info(response);
        result.put("base64Img", response);
        return result;

    }

    private static Integer getPtqrToken(String uuid) {

        char[] value = uuid.toCharArray();

        int e = 0;
        int n = 0;
        int r = 0;
        for (e = 0, n = 0, r = uuid.length(); n < r; ++n) {
            e += (e << 5) + charCodeAt(value[n]);
        }
        return 2147483647 & e;
    }

    public static int charCodeAt(char c) {
        int x;
        return x = (int) c;
    }

    @Override
    public AjaxResult getJccData(Map<String, Object> params) {
        String uuid = MapUtils.getString(params, "uuid");
        String type = MapUtils.getString(params, "type");
        String cookie = "";
        try {
            Integer ptqrToken = getPtqrToken(uuid);
            String ptqrlogin = "https://xui.ptlogin2.qq.com/ssl/ptqrlogin?u1=http%3A%2F%2Fconnect.qq.com&from_ui=1&type=1&ptlang=2052&ptqrtoken=" + ptqrToken + "&daid=381&aid=716027609&pt_3rd_aid=100543809&pt_openlogin_data=appid%3D716027609%26pt_3rd_aid%3D100543809%26daid%3D381%26pt_skey_valid%3D0%26style%3D35%26force_qr%3D1%26autorefresh%3D1%26s_url%3Dhttp%253A%252F%252Fconnect.qq.com%26refer_cgi%3Dm_authorize%26ucheck%3D1%26fall_to_wv%3D1%26status_os%3D16.0%26redirect_uri%3Dauth%253A%252F%252Fwww.qq.com%26client_id%3D100543809%26response_type%3Dtoken%26scope%3Dget_user_info%252Cget_simple_userinfo%26sdkp%3Di%26sdkv%3D3.5.11_lite%26state%3Dtest%26status_machine%3DiPhone13%252C2%26switch%3D1%26traceid%3DDEF697D1-75A6-4BFF-9200-6A181EC7CF60_1686454549%26_wv%3D16777218%26qr_login%3D1%26loginfrom%3Dmain%26h5sig%3DX8AeRmP9IoJru6y2o3KIdXYkiPMX6sKiy559pQ9FeYU%26loginty%3D7%26pt_flex%3D1%26loginfrom%3Dmain%26h5sig%3DX8AeRmP9IoJru6y2o3KIdXYkiPMX6sKiy559pQ9FeYU%26loginty%3D7%26&device=2&ptopt=1&pt_uistyle=35&jsver=v1.45.0&aegis_uid=1343701877&r=0.6518987684608579";

            Object cacheObject = redisCache.getCacheObject(uuid);
            if (Objects.isNull(cacheObject)) {
                throw new GlobalException("未查询到代理Ip");
            }
            String[] split = cacheObject.toString().split(":");
            cookie = HttpRequest.get(ptqrlogin)
                    .setHttpProxy(split[0], Integer.parseInt(split[1]))
                    .header("Cookie", "qrsig=" + uuid).execute().body();
            if (cookie.contains("二维码已失效")) {
                return AjaxResult.error("二维码已失效");
            } else if (cookie.contains("二维码未失效")) {
                return AjaxResult.success("二维码未失效");
            } else if (cookie.contains("二维码认证中")) {
                return AjaxResult.success("二维码认证中");
            } else if (cookie.contains("登录成功")) {
                //拿到appid、openid、access_token
                String replace = cookie.replace("ptuiCB('0','0','", "").replace("','0','登录成功！', 'C。', '')", "");
                String openid = getFieldValue(replace, "openid");
                String appid = getFieldValue(replace, "appid");
                String access_token = getFieldValue(replace, "access_token");

                JSONObject jccData = getJccData(openid, appid, access_token, new SysUser());

                return AjaxResult.success(jccData);
            } else {
                System.out.println("cookie=" + cookie);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new GlobalException(e.getMessage());
        }

        return null;
    }

    public JSONObject getJccData(String openid, String appid, String access_token, SysUser sysUser) {

        JSONObject result = new JSONObject();

        //获取皮肤数量、英雄数量、段位、已拥有皮肤

        //模拟掌上助手登录
        JSONObject loginParams = new JSONObject();
        loginParams.put("mcode", "37a1ed2a-e710-4e73-9e4b-f1ce4e6bff71");
        JSONObject config_params = new JSONObject();
        config_params.put("client_dev_name", "iPhone13,2");
        config_params.put("client_version", "9.6.1");
        config_params.put("lang_type", 0);
        loginParams.put("config_params", config_params);

        loginParams.put("clienttype", 10);
        loginParams.put("mappid", 10011);

        JSONObject login_info = new JSONObject();
        login_info.put("sig", access_token.trim());
        login_info.put("qq_info_type", 5);
        login_info.put("appid", Integer.parseInt(appid.trim()));
        login_info.put("openid", openid.trim());
        loginParams.put("login_info", login_info);

        String login_by_qq = "https://mlol.qt.qq.com/go/auth/login_by_qq";

        String userId = null;
        String wt = null;

        try {
            log.info(loginParams.toJSONString());

            //链式构建请求
            String result2 = HttpRequest.post(login_by_qq)
                    .header("content-type", "application/json")
                    .body(loginParams.toJSONString())//表单内容
                    .timeout(20000)//超时，毫秒
                    .execute().body();

//            String s = HttpUtils.sendPost(login_by_qq, loginParams.toJSONString(), new HashMap<>());
            log.info(result2);
            JSONObject jsonObject = JSONObject.parseObject(result2);
            JSONObject data = jsonObject.getJSONObject("data");
            if (Objects.nonNull(data)) {
                JSONObject login_info1 = data.getJSONObject("login_info");
                userId = login_info1.getString("user_id");
                wt = login_info1.getString("wt");
                log.info(userId);
                log.info(wt);
            } else {
                throw new GlobalException("模拟掌上助手登录参数错误");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


        //获取用户信息
        String user_profile = "https://mlol.qt.qq.com/go/user_profile/query/user?plat=ios&version=10000";

        String scene = null;

        //等级
        String level = "0";
        //小小英雄数量
        String heroNum = "0";
        //棋盘
        String qipanNum = "0";
        //攻击特效
        String gongjiNum = "0";

        JSONObject userParams = new JSONObject();
        userParams.put("opUuid", userId);
        userParams.put("isNeedMedal", 1);
        userParams.put("clientType", 10);
        userParams.put("isNeedMainInfo", 0);
        userParams.put("isNeedCommunityInfo", 1);
        List<JSONObject> uuidSceneList = new ArrayList<>();
        JSONObject uuid = new JSONObject();
        uuid.put("uuid", userId);
        uuidSceneList.add(uuid);
        userParams.put("uuidSceneList", uuidSceneList);
        userParams.put("isNeedGameInfo", 1);
        String result2 = HttpRequest.post(user_profile)
                .header("content-type", "application/json")
                .header("cookie", "userId=" + userId + ";tid=" + wt)
                .body(userParams.toJSONString())//表单内容
                .timeout(20000)//超时，毫秒
                .execute().body();

        log.info(result2);
        JSONObject jsonObject2 = JSONObject.parseObject(result2);
        String data = jsonObject2.getString("data");
        List<JSONObject> jsonObjects = JSONObject.parseArray(data, JSONObject.class);
        if (CollectionUtils.isNotEmpty(jsonObjects)) {
            JSONObject jsonObject = jsonObjects.get(0);
            String gameInfoList = jsonObject.getString("gameInfoList");
            List<JSONObject> jsonObjects1 = JSONArray.parseArray(gameInfoList, JSONObject.class);
//            List<JSONObject> collect = jsonObjects1.stream().filter(j -> j.getString("gameShortName").equals("LOL")
//            ).collect(Collectors.toList());
            List<JSONObject> collect =
                    jsonObjects1.stream().filter(j -> j.getString("gameShortName").equals("金铲铲")).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(collect)) {
                JSONObject jsonObject1 = collect.get(0);
                level = jsonObject1.getString("level");
                scene = jsonObject1.getString("scene");
                String areaName = jsonObject1.getString("areaName");
                if (areaName.contains("安卓")) {

                    result.put("system", "52526");
                    result.put("systemId", "52526");
                    result.put("systemName", "安卓");

                    if (areaName.contains("手Q")) {
                        result.put("carrier", "52529");
                        result.put("serve", "52535");
                        result.put("group", "52536");
                    } else {
                        result.put("carrier", "52530");
                        result.put("serve", "52533");
                        result.put("group", "52534");
                    }
                } else {
                    result.put("system", "52527");
                    result.put("systemId", "52527");
                    result.put("systemName", "苹果");

                    if (areaName.contains("手Q")) {
                        result.put("carrier", "52529");
                        result.put("serve", "52535");
                        result.put("group", "52536");
                    } else {
                        result.put("carrier", "52530");
                        result.put("serve", "52533");
                        result.put("group", "52534");
                    }
                }
//                result.put("server", "QQ");
//                result.put("serverId", "45988");
            }
        }
        result.put("level", level);

        String skinUrl = "https://mlol.qt.qq.com/go/jgame/get_property_detail?plat=ios&version=10000";

        JSONObject userSkin = new JSONObject();
        userSkin.put("scene", scene);
        userSkin.put("property_type", "tiny");

        String result3 = HttpRequest.post(skinUrl)
                .header(Header.USER_AGENT, "QTL/9.6.1 (iPhone; IOS 16.0; Scale/3.00)")
                .header("content-type", "application/json")
                .header("cookie", "userId=" + userId + ";tid=" + wt)
                .body(userSkin.toJSONString())//表单内容
                .timeout(20000)//超时，毫秒
                .execute().body();
        log.info(result3);
        JSONObject jsonObject1 = JSONObject.parseObject(result3);
        String result1 = jsonObject1.getString("result");
        List<JSONObject> skinJson = new ArrayList<>();
        if (Objects.equals("0", result1)) {
            String data1 = jsonObject1.getString("data");
            List<JSONObject> property_list = JSONArray.parseArray(data1, JSONObject.class);
//            setLolm(property_list);
            //异步自动添加属性
            for (JSONObject o : property_list) {
                JSONObject skinDetails = new JSONObject();
                String id = o.getString("id");
                skinDetails.put("id", id);
                String name = o.getString("name");
                skinDetails.put("name", name);
                String total = o.getString("total");
                skinDetails.put("total", total);
                skinJson.add(skinDetails);
            }
            result.put("heroNum", skinJson.size());
            result.put("skinList", skinJson);
        }
        //========================小小英雄已获取完成===================================//
        userSkin.put("property_type", "map");
        String resultMap = HttpRequest.post(skinUrl)
                .header(Header.USER_AGENT, "QTL/9.6.1 (iPhone; IOS 16.0; Scale/3.00)")
                .header("content-type", "application/json")
                .header("cookie", "userId=" + userId + ";tid=" + wt)
                .body(userSkin.toJSONString())//表单内容
                .timeout(20000)//超时，毫秒
                .execute().body();
        JSONObject jsonObjectMap = JSONObject.parseObject(resultMap);
        String resultMap1 = jsonObjectMap.getString("result");
        List<JSONObject> mapJson = new ArrayList<>();
        if (Objects.equals("0", resultMap1)) {
            String data1 = jsonObjectMap.getString("data");
            List<JSONObject> property_list = JSONArray.parseArray(data1, JSONObject.class);
            for (JSONObject o : property_list) {
                JSONObject skinDetails = new JSONObject();
                String id = o.getString("id");
                skinDetails.put("id", id);
                String name = o.getString("name");
                skinDetails.put("name", name);
                mapJson.add(skinDetails);
            }
            result.put("mapNum", mapJson.size());
            result.put("mapJson", mapJson);
        }
        //============================竞技场已获取==============================//
        userSkin.put("property_type", "attach");
        String resultattach = HttpRequest.post(skinUrl)
                .header(Header.USER_AGENT, "QTL/9.6.1 (iPhone; IOS 16.0; Scale/3.00)")
                .header("content-type", "application/json")
                .header("cookie", "userId=" + userId + ";tid=" + wt)
                .body(userSkin.toJSONString())//表单内容
                .timeout(20000)//超时，毫秒
                .execute().body();
        JSONObject jsonObjectatt = JSONObject.parseObject(resultattach);
        String resultatt = jsonObjectatt.getString("result");
        List<JSONObject> mapatt = new ArrayList<>();
        if (Objects.equals("0", resultatt)) {
            String data1 = jsonObjectatt.getString("data");
            List<JSONObject> property_list = JSONArray.parseArray(data1, JSONObject.class);
            for (JSONObject o : property_list) {
                JSONObject skinDetails = new JSONObject();
                String id = o.getString("id");
                skinDetails.put("id", id);
                String name = o.getString("name");
                skinDetails.put("name", name);
                mapatt.add(skinDetails);
            }
            result.put("attNum", mapatt.size());
            result.put("attJson", mapatt);
        }
        //============================攻击特效已获取==============================//

        return result;
    }

    /**
     * 获取字段值
     *
     * @param urlStr
     * @param field
     * @return
     */
    private static String getFieldValue(String urlStr, String field) {
        String result = "";
        Pattern pXM = Pattern.compile(field + "=([^&]*)");
        Matcher mXM = pXM.matcher(urlStr);
        while (mXM.find()) {
            result += mXM.group(1) + "\t\t";
        }
        return result;
    }
}
